getBoundsZoomLevel - how to use with API v3?

3,941 views
Skip to first unread message

Pit

unread,
Jun 23, 2009, 6:29:48 AM6/23/09
to Google Maps JavaScript API v3
Hey guys.

I started working on a project using the Google Maps API v3 yesterday.
I'm going to use the map as a membermap for a clan cms (webSpell)
based on the mysql-databse. It's working, and I don't get any errors.
But there is one thing: the correct zoom and center location. For
every user (or city, if there are more users in a city) there is a
marker, and I wanted to base the centerlocation and the zoom on all
those markers, using the following script:

function fitMap (map, markers) {
var bounds = new google.maps.LatLngBounds();
for (var _marker in markers) {
bounds.extend(markers[_marker]);
}
map.set_zoom(map.getBoundsZoomLevel(bounds));
map.set_center(bounds.getCenter());
}

If I open the page, firebug throws out the following error:
map.getBoundsZoomLevel is not a function

So, my question is: how do I use getBoundsZoomLevel with API v3? I
only found it for v2. For the whole script, visit
http://www.apocalyptic-death.de/googlemaps.php (there is no php-code
at all, don't care about the extension). As you might see, I set the
current location by hand that Germany, Austria and Swiss are at least
shown, but thats not perfect. Hope you are able to help me.

Best Regards,
PitBull

Mike Williams

unread,
Jun 23, 2009, 7:08:50 AM6/23/09
to google-map...@googlegroups.com
There is no map.getBoundsZoomLevel in v3.

There is, however, a map.fitBounds() Method.

--
Mike Williams
Gentleman of Leisure

Pit

unread,
Jun 23, 2009, 12:15:03 PM6/23/09
to Google Maps JavaScript API v3
Thanks for that. I updated the script, but it does not work/it won't
fit the map. Link again: http://www.apocalyptic-death.de/googlemaps.php

Mike Williams

unread,
Jun 23, 2009, 5:11:15 PM6/23/09
to google-map...@googlegroups.com
Geocoding is asynchronous.

You attempt to fit the bounds immediately after the geocoding requests
are sent to the server.

Some time later the geocode replies come back, and you extend the
bounds, but by then it's too late.

Pit

unread,
Jun 24, 2009, 4:23:53 AM6/24/09
to Google Maps JavaScript API v3
Thank you very much for the tip, I got it working now.

Best Regards,
Pit
Reply all
Reply to author
Forward
0 new messages