Reputation: 25
I'm fairly new to the Maps API, and I'm trying to work with a map in Sencha Touch.
I have an array of markers plotted on the map successfully. But I want to zoom and center the map to fit all the markers as tightly as possible.
When I call the fitBounds function, I get a view of the map in which all my markers are in the top left corner of the screen and the zoom is far too wide - not what I want.
Any tips on how to get all my markers on the map view with the closest possible zoom? Thanks!
function setCenter()
{
var bounds = new google.maps.LatLngBounds();
for (var i = 0, LtLgLen = LatLngList.length; i < LtLgLen; i++) {
// And increase the bounds to take this point
bounds.extend (LatLngList[i]);
}
map.getMap().fitBounds(bounds);
}
Upvotes: 2
Views: 1651
Reputation: 1311
what I use (after the for loop):
map_center = bounds.getCenter();
map.setCenter(map_center);
map.panToBounds(bounds);
map.fitBounds(bounds);
hope it helps!
Upvotes: 3