1

In my app, I'm plotting 15-30 markers on the map and letting the user select a marker. Currently the map's original zoom level shows the entirety of North and South America. Not quite ideal.

I'd like to zoom the camera just enough so that all the markers are contained on screen. Finding the the center and necessary radius is fairly trivial, but once I have this distance (in meters or LAT/LONG), how can I set the zoom level to contain this appropriately? The scale settings seem arbitrary and dependent on the device, so I'm pretty confused.

Thanks.

mMap = googleMap;

setMapMarkerListener();

HashMap<Integer, LatLng> mappedGeoCoords = UserValues.getInstance().geo;
LatLng anchor = null;
for(int i = 0; i<stops.size(); i++){
    //Set all my markers
}
LatLng center = something;

float zoom = ??;
if(anchor!=null)
    mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(anchor, zoom));
Nat
  • 890
  • 3
  • 11
  • 23
  • Take a look at the `LatLngBounds` class. For example: http://stackoverflow.com/questions/14828217/android-map-v2-zoom-to-show-all-the-markers Coupled with the `CameraUpdateFactory.newLatLngBounds(bounds, padding);` method, you can zoom to a box that includes all your markers! – stkent Apr 10 '16 at 01:56

0 Answers0