2014-12-16 3 views
0

사용자의 기호에 따라 변경할 수있는 순환 오버레이가 있습니다. 주변에 반경이 'r'인 원이 있으며 슬라이더에 따라 'r'을 변경할 수 있습니다. 지금까지 완벽하게 잘 작동합니다.지도 - 거리 변환에 대한 원 오버레이

내 문제는 원의 반경에서지도의 측정 기준으로 적절한 변환을 찾는 방법을 모르겠다. 예를 들어 아래의 원이 주어지면 주어진 반경으로 덮여있는 거리는 얼마입니까?

enter image description here

+0

사실, 나는 [this] (https://code.google.com/p/osmdroid/source/browse/trunk/osmdroid-android/src/main/java/org/osmdroid/views/)를 따르고 있습니다. overlay/ScaleBarOverlay.java? r = 1152) 바로 지금 내 문제의 해결책이라고 생각합니다. 알아 낸다면이 스레드를 업데이트 할 것입니다. – Matt

답변

1

당신이 보여주고있다지도의 축척이 무엇인지 알아야합니다. 지도의 크기를 조정하면 픽셀 크기를 미터 크기로 변환 할 수 있습니다. 이 비율을 사용하면 픽셀 단위로 반경을 미터로 변환 할 수 있습니다. 그래서 여기

0

Jedil 당신은 내가 그렇다고 밖으로이 생각 this old osmdroid 소스를 통해 찾고, 그래서 등 화면 너비/높이, 화면의 dpi의를 찾아야 올바른 ... 당신이 그것을 할 방법은 다음과 같습니다

//Get the x and y dpi 
this.xdpi = this.context.getResources().getDisplayMetrics().xdpi; 
this.ydpi = this.context.getResources().getDisplayMetrics().ydpi; 

//Get the screen width/height 
this.screenWidth = this.context.getResources().getDisplayMetrics().widthPixels; 
this.screenHeight = this.context.getResources().getDisplayMetrics().heightPixels; 

// DPI corrections for specific models 
String manufacturer = null; 
try { 
     final Field field = android.os.Build.class.getField("MANUFACTURER"); 
     manufacturer = (String) field.get(null); 
     } catch (final Exception ignore) { 
     } 

if ("motorola".equals(manufacturer) && "DROIDX".equals(android.os.Build.MODEL)) { 

// If the screen is rotated, flip the x and y dpi values 
WindowManager windowManager = (WindowManager) this.context 
         .getSystemService(Context.WINDOW_SERVICE); 
if (windowManager.getDefaultDisplay().getOrientation() > 0) { 
    this.xdpi = (float) (this.screenWidth/3.75); 
    this.ydpi = (float) (this.screenHeight/2.1); 
} else { 
     this.xdpi = (float) (this.screenWidth/2.1); 
     this.ydpi = (float) (this.screenHeight/3.75); 
} 

} else if ("motorola".equals(manufacturer) && "Droid".equals(android.os.Build.MODEL)) { 
    // http://www.mail-archive.com/[email protected]/msg109497.html 
    this.xdpi = 264; 
    this.ydpi = 264; 
} 

// set default max length to 1 inch 
maxLength = 2.54f; 

"상수"를 얻는 방법입니다 (적어도 기기의 눈에는). (: screenHeight을 사용 힌트)를 yMeters를 얻을 수 문제, ...

// calculate dots per centimeter 
int xdpcm = (int) ((float) xdpi/2.54); 
int ydpcm = (int) ((float) ydpi/2.54); 

// get length in pixel 
int xLen = (int) (maxLength * xdpcm); 
int yLen = (int) (maxLength * ydpcm); 


// Two points, xLen apart, at scale bar screen location 
IGeoPoint p1 = projection.fromPixels((screenWidth/2) - (xLen/2), yOffset); 
IGeoPoint p2 = projection.fromPixels((screenWidth/2) + (xLen/2), yOffset); 

// get distance in meters between points 
final int xMeters = ((GeoPoint) p1).distanceTo(p2); 

변환 ... 그리고 거의 동일하지 않은 경우는 유사합니다.

분명히, 나는 회선 IGeoPoint...이 무엇을하고 있는지 완전히 확신하지 못한다. 그러나 나는 변환이 있다는 것을 깨닫는다. 이것을 원하면 미래에 누군가를 도울 수 있습니다. 위의 코드를 더 잘 이해하려면 게시 한 링크를 참조하십시오.

0

당신이 찾고있는 것은 미터 - 픽셀 계산입니다. 당신은 투사에서이를 얻을 수 있습니다 :

// Get projection 
Projection proj = mMapView.getProjection(); 
// How many pixels in 100 meters for this zoom level 
float pixels = proj.metersToPixels(100); 
// How many meters in 100 pixels for this zoom level 
float meters = 1/proj.metersToPixels(1/100); 
// You could also get a raw meters-per-pixels value by using TileSystem.GroundResolution() 

두 가지 기억 -이 값은 어떤 줌 레벨을 기준으로하지만 당신은지도에있는 위도 내용에 따라뿐만 아니라 변경됩니다.

관련 문제