How to zoom in on MapView, so it always includes two geo-integrations?

I have two geometry points that change intermittently and want the MapView to resize and translate to make sure that both points are always visible. I can easily reorient the map to a point between them, but how do I set the zoom level to make sure my two points are visible?

+4
source share
3 answers

Try this and see:

double latitudeSpan = Math.round(Math.abs(firstLat - secLat)); double longitudeSpan = Math.round(Math.abs(firstLong - secLong)); double currentLatitudeSpan = (double)mapView.getLatitudeSpan(); double currentLongitudeSpan = (double)mapView.getLongitudeSpan(); double ratio = currentLongitudeSpan/currentLatitudeSpan; if(longitudeSpan < (double)(latitudeSpan+2E7) * ratio){ longitudeSpan = ((double)(latitudeSpan+2E7) * ratio); } mapController.zoomToSpan((int)(latitudeSpan*2), (int)(longitudeSpan*2)); mapView.invalidate(); 
+4
source

Check your answer in another post: Google Map V2 how to configure ZoomToSpan?

He solves it without much hassle. Please note that you can only use this function after the map has been loaded at least once. If you do not use the function with the specified map size on the screen

 LatLngBounds bounds = new LatLngBounds.Builder() .include(new LatLng(CURRENTSTOP.latitude, CURRENTSTOP.longitude)) .include(new LatLng(MYPOSITION.latitude, MYPOSITION.longitude)).build(); Point displaySize = new Point(); getWindowManager().getDefaultDisplay().getSize(displaySize); map.moveCamera(CameraUpdateFactory.newLatLngBounds(bounds, displaySize.x, 250, 30)); 

Works like a charm and is very dynamic!

+5
source

in the new Maps API (v2) you can do it like this:

 LatLng southwest = new LatLng(Math.min(laglng1.latitude, laglng2.latitude), Math.min(laglng1.longitude, laglng2.longitude)); LatLng northeast = new LatLng(Math.max(laglng1.latitude, laglng2.latitude), Math.max(laglng1.longitude, laglng2.longitude)); googleMap.moveCamera(CameraUpdateFactory.newLatLngBounds(new LatLngBounds(southwest, northeast),500,500, 0)); 
0
source

All Articles