On Jul 27, 1:54 pm, randatgoo <[email protected]> wrote:
> I am adding multiple markers, but my problem is some markers lay
> outside of the map display boundaries.  If I zoom out then I can see
> all markers.  My questions is how do I ensure all markers are visible
> to user on map load?  In other words, I want the map to be zoomed in
> as much as possible while keeping all markers in view.
>
> Is there API method to do this easily?  or a standard algorithm?
Add the GLatLng associated to each marker to a GLatLngBounds object
var bounds = new GLatLngBounds();
then in the loop that creates your markers (or as you add each
marker):
bounds.extent(latlng);

then after you have added all the markers, do this:
map.setCenter(bounds.getCenter(),map.getBoundsZoomLevel(bounds));

examples:
http://www.geocodezip.com/GenericMapBrowser.asp?filename=F18CrashSite081208.xml&type=hybrid
http://www.geocodezip.com/GenericMapBrowser.asp?filename=SteveFossett.xml

  -- Larry

-- 
You received this message because you are subscribed to the Google Groups 
"Google Maps API" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-maps-api?hl=en.

Reply via email to