I have a set of points I want to plot on an embedded Google Map (API v3). I’d like the bounds to accommodate all points unless the zoom level is too low (i.e., zoomed out too much). My approach has been like this: var bounds = new google.maps.LatLngBounds(); // extend bounds with each point gmap.fitBounds(bounds); [...]

Autor:

I have a set of points I want to plot on an embedded Google Map (API v3). I’d like the bounds to accommodate all points unless the zoom level is too low (i.e., zoomed out too much). My approach has been like this:

var bounds = new google.maps.LatLngBounds();

// extend bounds with each point

gmap.fitBounds(bounds);
gmap.setZoom( Math.max(6, gmap.getZoom()) );

This doesn’t work. The last line “gmap.setZoom()” doesn’t change the zoom level of the map if called directly after fitBounds.

Is there a way to get the zoom level of a bounds without applying it to the map? Other ideas to solve this?

Related posts:

  1. Google Maps API v3: Can I setZoom after fitBounds?
  2. Google Maps V3 – How to calculate the zoom level for a given bounds
  3. Google maps watchposition { setzoom() } overrides user zooming
  4. Google maps watchposition { setzoom() } overrides user zooming
  5. How to affect the "grace margin" of map.fitBounds()

Comments on this entry (no comments)

Did you like this post? You can share your opinion with us! Simply click here.

Add Your Comment