Reputation: 6246
I'm setting a map to fitBounds using this line
var bounds = new google.maps.LatLngBounds(fromLoc, theLoc);
console.log(bound);
map.fitBounds(bounds);
As you can see when that line runs the map fully zooms out despite the 2 LatLng's only being around 20 minutes drive away.
Anyone know how I can fix this?
Upvotes: 0
Views: 245
Reputation: 161404
When you do this:
var bounds = new google.maps.LatLngBounds(fromLoc, theLoc);
You are creating a google.maps.LatLngBounds with the southWest corner at fromLoc and the northEast corner at theLoc.
To make a bounds that contains those two locations, do this instead:
var bounds = new google.maps.LatLngBounds(); // empty bounds
bounds.extend(fromLoc);
bounds.extend(theLoc);
map.fitBounds(bounds);
Upvotes: 2