MapView and MapboxMap

Prior to version 4.0.0, the Mapbox Android SDK relied on the MapView class to handle everything from creating a view for your Mapbox maps to setting the camera position and handling user interaction. In version 4.0.0 and later, the classes and methods that used to be under MapView have been split into two classes: MapView and MapboxMap.

What is MapboxMap?

You can think of MapboxMap as the controller class for your map and MapView as a more traditional View class. MapboxMap is now home to the methods you’ll use to set and move camera position, add markers, configure user interactions, draw shapes, customize infoWindows, and more.

How to use MapboxMap and MapView in your application

You can retrieve MapboxMap using getMapAsync():

mMapView.getMapAsync(new OnMapReadyCallback() {
    @Override
    public void onMapReady(@NonNull MapboxMap mapboxMap) { ...

Set your map’s camera position using mapboxMap.moveCamera():

mapboxMap.moveCamera(CameraUpdateFactory.newCameraPosition(
    new CameraPosition.Builder()
    .target(new LatLng(43.876550, -103.454791))  // set the camera's center position
    .zoom(14)  // set the camera's zoom level
    .tilt(20)  // set the camera's tilt
    .build()));

For more examples, see our Mapbox Android SDK documentation.

Additional questions? Ask our support team or learn more about How Mapbox Works.