fitbounds() in Google maps api V3 does not fit bounds

Posted by jul on Stack Overflow See other posts from Stack Overflow or by jul
Published on 2010-03-22T18:28:54Z Indexed on 2010/03/22 18:31 UTC
Read the original article Hit count: 839

Filed under:
|
|
|
|

hi,

I'm using the geocoder from Google API v3 to display a map of a country. I get the recommended viewport for the country but when I want to fit the map to this viewport, it does not work (see the bounds before and after calling the fitBounds function in the code below).

What am I doing wrong?

How can I set the viewport of my map to results[0].geometry.viewport?

thanks

jul

var geocoder = new google.maps.Geocoder();
if(geocoder) {
    geocoder.geocode({'address': '{{countrycode}}'}, function(results, status) {
        var bounds = new google.maps.LatLngBounds();
        bounds = results[0].geometry.viewport;
        console.log(bounds); //((35.173, -12.524), (45.244, 5.098))
        console.log(map.getBounds()); //((34.628757195038844, -14.683750000000012), (58.28355197864712, 27.503749999999986))
        map.fitBounds(bounds);               
        console.log(map.getBounds()); //((25.740113512090183, -24.806750000000005), (52.44233664523719, 17.380749999999974))
    });
}


}

© Stack Overflow or respective owner

Related posts about google

Related posts about maps