6
votes

I'm using Mapbox Android SDK v4.0.0 in an Android app that at some point needs to "freeze" a MapView at a given position and a given zoom level.

It seems to me that there are no methods in the API to:

  1. Set a specific zoom level for a map,
  2. Center a map on a given location.

How to get this done?

1

1 Answers

18
votes

It seems the API has changed between versions 3.2.0 and 4.0.0. Currently, to achieve the above goal, you need to use a CameraPosition and inject it into your mapboxMap:

mapView.getMapAsync(new OnMapReadyCallback() {
    @Override
    public void onMapReady(MapboxMap mapboxMap) {
        mapboxMap.setCameraPosition(new CameraPosition.Builder()
                .target(yourLatLng)
                .zoom(yourZoom)
                .build());
    }
});

Works like a charm.