我想知道在給定的縮放級別,有多少米是特定的像素距離。獲取以米爲單位的像素距離mapView
原因:我想知道半徑,以米爲單位,在MapView的一個循環,這非常適合在的MapView的 - >radiusPixels = mapView.getWidth()/2;
我找到了方法mapView.getProjection().metersToEquatorPixels(radiusMeters)
,這確實的是,相反的我需要。但是這種方法或其他任何有用的東西都沒有反轉。
我(可能天真)的方法來解決這個問題如下:
private double getFittingRadiusInMeters() {
return getMeters(mapView.getWidth()/2);
}
private double getMeters(int pixels) {
Projection proj = mapView.getProjection();
Point mapCenterPixels = new Point(mapView.getWidth()/2, mapView.getHeight()/2);
//create 2 geopoints which are at pixels distance
GeoPoint centerGeoPoint = proj.fromPixels(mapCenterPixels.x, mapCenterPixels.y);
GeoPoint otherGeoPoint = proj.fromPixels(mapCenterPixels.x + pixels, mapCenterPixels.y);
Location loc = new Location("");
loc.setLatitude(centerGeoPoint.getLatitudeE6()/1E6);
loc.setLongitude(centerGeoPoint.getLongitudeE6()/1E6);
Location loc2 = new Location("");
loc2.setLatitude(otherGeoPoint.getLatitudeE6()/1E6);
loc2.setLongitude(otherGeoPoint.getLongitudeE6()/1E6);
return loc.distanceTo(loc2);
}
但它不能很好地工作。我總是得到比mapView小得多的圓 - 半徑太小。
我知道distanceTo方法表示「近似」,但半徑與預期大小有很大不同。不應該是近似的效果。
謝謝。