Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to calculate the map span/zoom to include a set of GeoPoints in the viewport?
    primarykey
    data
    text
    <p>I have a set of GeoPoints and want to find the Lat/Lon center and and spans that include all these GeoPoints (so they're visible all on the MapView).</p> <p>On a planar map this would be rather simple, find the highest and lowest x/y values, find the center by adding half of the absolute distance to the lower value.</p> <p>But how is this done for the spherical world map, where the max/min values of -180/+180 and +90/-90 are next to each other? </p> <p>Here's what I'm trying to do:</p> <pre><code>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)); </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload