setbounds on google maps api v3

11,952

If I'm not mistaken, I'm assuming you want all your points to be visible on the map with the highest possible zoom level. I accomplished this by initializing the zoom level of the map to 16(not sure if it's the highest possible zoom level on V3).

var map = new google.maps.Map(document.getElementById('map_canvas'), { zoom: 16
                                        , center: marker_point
                                        , mapTypeId: google.maps.MapTypeId.ROADMAP
});

Then after that I did the bounds stuff:

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

//you can have a loop here of all you marker points
//begin loop
bounds.extend(marker_point);
//end loop

map.fitBounds(bounds);

Result: Success!

Share:
11,952
msaspence
Author by

msaspence

Updated on June 20, 2022

Comments

  • msaspence
    msaspence almost 2 years

    I'm trying to set the bounds of a map fitbounds doesnt work because it puts some space around the bounds therefore doing

    {{{map.fitBounds(map.getBounds())}}}
    

    a few times will quickly zoom the map out

    I need to be able to do

    {{{map.setBounds(map.getBounds())}}}
    

    and for nothing to happen

    please note I am using v3 of the api and therefore do not have access to getBoundsZoomLevel