I have a cluster marker that defines a bounding rectangle containing a group of markers. The cluster has a center (lat,lon), a marker count and a latitude and longitude span to calculate the bounds.
The Google Maps API (JS) has a function called "getBoundsZoomLevel(bounds)" but I cannot find an equivalent method in the Google Maps SDK for Android. How can I estimate the zoom level for given bounds (especially on different devices with different resolutions/densitys)?
I've planned that an user can touch a cluster marker and the map view will be centered to the center and the bounds of that cluster.
Has anybody a working code snippet or some suggestions for me?
Thanks in advance Regards Thorsten.
Convert latitude, longitude to spherical mercator x, y. Get distance between your two points in spherical mercator. The equator is about 40m meters long projected and tiles are 256 pixels wide, so the pixel length of that map at a given zoom level is about 256 * distance/40000000 * 2^zoom.
Users can zoom the map by clicking the zoom controls. They can also zoom and pan by using two-finger movements on the map for touchscreen devices.
The shortcut is simple: just double-tap the maps interface, but instead of lifting your finger after the second tap (the shortcut for zooming in), you leave it touching the screen. Then a swipe up zooms out, and a swipe down zooms in.
Google Maps - The Default Controls Zoom - displays a slider or "+/-" buttons to control the zoom level of the map. Pan - displays a pan control for panning the map.
Thank you for your answer Solvek. Meanwhile I found a solution that I've adapted slightly and it works. The method computes the bounds of a set of geo points, computes the span of these points and finally uses zoomToSpan and animateTo for zooming into and centering the given area:
public static void zoomInBounds(final MapView view, final GeoPoint.. bounds) {
int minLat = Integer.MAX_VALUE;
int minLong = Integer.MAX_VALUE;
int maxLat = Integer.MIN_VALUE;
int maxLong = Integer.MIN_VALUE;
for (GeoPoint point : bounds) {
minLat = Math.min(point.getLatitudeE6(), minLat);
minLong = Math.min(point.getLongitudeE6(), minLong);
maxLat = Math.max(point.getLatitudeE6(), maxLat);
maxLong = Math.max(point.getLongitudeE6(), maxLong);
}
final MapController controller = view.getController();
controller.zoomToSpan(
Math.abs(minLat - maxLat), Math.abs(minLong - maxLong));
controller.animateTo(new GeoPoint((maxLat + minLat) / 2,
(maxLong + minLong) / 2));
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With