Overview

Camera Engine

Before you begin reading this document, you might want to begin with the general overview and basics of the map's camera.

MapboxNavigation creates a SimpleCamera by default that you can access with theMapboxNavigation#getCameraEngine() method.

SimpleCamera extends from Camera and is required to provide values for bearing, tilt, zoom, and a target Point given a RouteInformation.

A RouteInformation object can be created from a DirectionsRoute, Location, or RouteProgress. Depending on which objects are provided, SimpleCamera will return a value for each camera method:

RouteInformation.create(DirectionsRoute route, Location location, RouteProgress routeProgress);

For example, if RouteInformation has a Location, the SimpleCamera will return theLocationBearing for the camera bearing. This bearing value represents the GPS system's understanding of where the user is going:

@Override
public double bearing(RouteInformation routeInformation) {
if (routeInformation.location() != null) {
return routeInformation.location().getBearing();
}
return 0;
}

You can then use the returned bearing to update the MapboxMap camera:

double bearing = cameraEngine.bearing(routeInformation);
CameraPosition position = new CameraPosition.Builder()
.bearing(bearing)
.build();
mapboxMap.easeCamera(CameraUpdateFactory.newCameraPosition(position));

Creating a custom Camera

The Navigation SDK provides a SimpleCamera by default. You're also able to create your own CameraEngine and give it to the Navigation SDK like so: MapboxNavigation#setCameraEngine(CameraEngine cameraEngine).

An example of this would be the DynamicCamera provided by the libandroid-navigation-uilibrary. In DynamicCamera, calculations are being made based on the user's location along the given route.