Search code examples
google-mapsgoogle-maps-api-2

Best zoom to points in google maps api v2


How can I best zoom to group of points in google maps api v2? In api v3 I would use bounds object to store the points and then zoom to these bounds using fitBounds() function, but in v2 I really don't know.

I found some advice here, but the solution of writing custom function seems quite clumsy... http://groups.google.com/group/Google-Maps-API/browse_thread/thread/996f83e075e51fdf


Solution

  • Try this mini tutorial, it sounds like what you want:

    http://econym.org.uk/gmap/basic14.htm

    var bounds = new GLatLngBounds();
    for (... each point ...) {
        bounds.extend(latlng); 
    }
    map.setZoom(map.getBoundsZoomLevel(bounds));
    map.setCenter(bounds.getCenter());
    

    http://econym.org.uk/gmap/example_map14.htm