How do I set view to see all markers on map in Mapbox or Leaflet? Like Google Maps API does with bounds
?
E.g:
var latlngbounds = new google.maps.LatLngBounds();
for (var i = 0; i < latlng.length; i++) {
latlngbounds.extend(latlng[i]);
}
map.fitBounds(latlngbounds);
The 'Answer' didn't work for me some reasons. So here is what I ended up doing:
Leaflet also has LatLngBounds that even has an extend function, just like google maps.
http://leafletjs.com/reference.html#latlngbounds
So you could simply use:
The rest is exactly the same.
See the documetation for more info.
For Leaflet, I'm using
You also can locate all features inside a FeatureGroup or all the featureGroups, see how it works!