Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I read current zoom level of Mapbox?

Tags:

mapbox

I have a back to home function

function panToHome(){
    latLng = [current.lat, current.lng];
    map.setView(latLng, 8);
}

I want to save the current view as history, so user can switch back as they might click mistakely. So the question is how can I know the current latlng on Mapbox?!

like image 678
Weijing Jay Lin Avatar asked Feb 24 '16 22:02

Weijing Jay Lin


3 Answers

Use the getZoom method on your L.mapbox.map instance:

Returns the current zoom of the map view.

http://leafletjs.com/reference.html#map-getzoom

var mapbox = new L.mapbox.map('mapbox', 'mapbox.streets', {
    'center': [0, 0],
    'zoom': 9
});

var zoom = mapbox.getZoom();

Here zoom holds 9

like image 81
iH8 Avatar answered Nov 13 '22 09:11

iH8


In Android you can use

int currentZoomLevel = mapboxMap.getCameraPosition().zoom;
like image 43
Linh Avatar answered Nov 13 '22 09:11

Linh


On iOS with Mapbox SDK 4.0, there's a .zoomLevel property on the MGLMapView object.

like image 29
bmt22033 Avatar answered Nov 13 '22 09:11

bmt22033