Skip to content Skip to sidebar Skip to footer

Google Maps V3 Api Extend Bounds. Javascript How-to?

function initialize(){ // Creating a map var map = new google.maps.Map(document.getElementById('map'), { zoom: 10, center: new google.maps.LatLng(53.0123601276819, -2.445191643

Solution 1:

You need to pass a LatLng object to the bounds.extend function.

Here is the code :

....
bounds.extend(new google.maps.LatLng(lat, lng));
....

Solution 2:

Here is a clarification of the above answer which is correct except it's missing a parenthesis and a little brief.

//make an empty bounds variablevar bounds = new google.maps.LatLngBounds();


//do your map stuff here//special note: make sure your lat and lng are floats or googleMaps will errorvar lat = 38.103;
var lng = -121.572;
bounds.extend(new google.maps.LatLng(lat, lng));


//adjust the viewport of the map//special note: this only needs to be done once, don't put it in a loopmap.fitBounds(bounds);

Post a Comment for "Google Maps V3 Api Extend Bounds. Javascript How-to?"