特定のズームレベルで、特定のピクセル距離がどのくらいのメートルであるかを知りたいです。
理由: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メソッドが「概算」と言っていることは知っていますが、半径が予想されるサイズと大幅に異なります。近似の効果であってはなりません。
ありがとう。