如何读取 Mapbox 的当前缩放级别?

How can I read current zoom level of Mapbox?

我有回家功能

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

我想将当前视图保存为历史记录,这样用户就可以切换回来,因为他们可能会误点击。所以问题是我如何知道 Mapbox 上的当前 latlng?!

在您的 L.mapbox.map 实例上使用 getZoom 方法:

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();

此处zoom持有9

在Android中你可以使用

int currentZoomLevel = mapboxMap.getCameraPosition().zoom;

在使用 Mapbox SDK 4.0 的 iOS 上,MGLMapView 对象上有一个 .zoomLevel 属性。