Center and zoom map based on markers

644 views
Skip to first unread message

bnazza

unread,
Jun 21, 2011, 4:21:20 PM6/21/11
to google-map...@googlegroups.com
I want to create a map, add a number of markers, let's say 10 and then have the map center and zoom so that the markers "fill" the map.

The only way I can think to do this at the moment is to calculate the northernmost and southernmost latitude co-ordinates, the easternmost and westernmost longitude co-ordinates and figure a center co-ordinate from there.

Is there an easier way to achieve this in V3?

Luke Mahé

unread,
Jun 22, 2011, 1:24:50 AM6/22/11
to google-map...@googlegroups.com
Have a look at the LatLngBounds object and using map.fitBounds.


-- Luke


--
You received this message because you are subscribed to the Google Groups "Google Maps JavaScript API v3" group.
To view this discussion on the web visit https://groups.google.com/d/msg/google-maps-js-api-v3/-/xR5h5jC5VJMJ.
To post to this group, send email to google-map...@googlegroups.com.
To unsubscribe from this group, send email to google-maps-js-a...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-maps-js-api-v3?hl=en.

EmmaS

unread,
Jun 22, 2011, 11:54:12 AM6/22/11
to Google Maps JavaScript API v3
My favorite way to achieve this is to include my markers as a KML
overlay. From http://code.google.com/apis/maps/documentation/javascript/overlays.html#KMLLayers:
"By default, when displaying a KmlLayer, the map is zoomed and
positioned to show the entirety of the layer's contents."

ES

On Jun 21, 10:24 pm, Luke Mahé <lu...@google.com> wrote:
> Have a look at the LatLngBounds object and using map.fitBounds.
>
> http://code.google.com/apis/maps/documentation/javascript/reference.h...http://code.google.com/apis/maps/documentation/javascript/reference.h...
Reply all
Reply to author
Forward
0 new messages