一連のGeoPointがあり、Lat / Lonの中心と、これらすべてのGeoPointを含むスパンを検索したいと思います(したがって、これらはすべてMapViewに表示されます)。
平面マップでは、これはかなり単純です。最高と最低のx / y値を見つけ、絶対距離の半分を低い値に追加して中心を見つけます。
しかし、-180 /+180と+90/ -90の最大/最小値が隣り合っている球形の世界地図では、これはどのように行われますか?
これが私がやろうとしていることです:
public void zoomToGeoPoints(GeoPoint... geoPoint) {
MapController mc = getController();
if (geoPoint == null) {
Log.w(TAG, "No geopoints passed, doing nothing!");
return;
}
// Set inverse max/min start values
int maxLat = (int) (-90 * 1E6);
int maxLon = (int) (-180 * 1E6);
int minLat = (int) (90 * 1E6);
int minLon = (int) (180 * 1E6);
// Find the max/min values
for (GeoPoint gp : geoPoint) {
maxLat = Math.max(maxLat, gp.getLatitudeE6());
maxLon = Math.max(maxLon, gp.getLongitudeE6());
minLat = Math.min(minLat, gp.getLatitudeE6());
minLon = Math.min(minLon, gp.getLongitudeE6());
}
// Find the spans and center point
double spanLat = Math.abs(maxLat - minLat);
double spanLon = Math.abs(maxLon - minLon);
int centerLat = (int) ((minLat + spanLat / 2d));
int centerLon = (int) ((minLon + spanLon / 2d));
GeoPoint center = new GeoPoint(centerLat, centerLon);
// Pan to center
mc.animateTo(center);
// Zoom to include all GeoPoints
mc.zoomToSpan((int)(spanLat), (int)(spanLon));