MapQuest Maps Android SDK

User Location and Follow Mode

Showing the user location is an important part of using our Maps SDK with the NavSDK. Use the MyLocationPresenter class to present the user's location.

User Location View

Setup and Using the Location Layer

You'll need to include either the coarse or fine location permission inside your applications manifest.:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.myapp" >
  ...
  <!-- Coarse location -->
  <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>

  <!-- Or fine location -->
  <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
  ...
</manifest>

If your application's targeting Android 6.0 (API 23) or higher, you'll want to use the new permissions model which request permissions at runtime rather than during the installation process. It's important to request the permission either during the application startup or when the location layer gets initialized.

@SuppressWarnings( {"MissingPermission"})
private void requestPermissions() {

    // Check if permissions are enabled and if not request
    if (PermissionsManager.areLocationPermissionsGranted(this)) {
        // Create a location engine instance
        initializeLocationEngine();
    } else {
        permissionsManager = new PermissionsManager(new PermissionsListener() {

            @Override
            public void onExplanationNeeded(List permissionsToExplain) {
                // Left blank on purpose
            }

            @Override
            public void onPermissionResult(boolean granted) {
                if (granted) {
                    initializeLocationEngine();
                }
            }

        });
        permissionsManager.requestLocationPermissions(this);
    }
}

Entering Follow Mode when using the MapQuest Navigation SDK

When using the Location Layer plugin with the MapQuest Navigation SDK, there are some behaviors you may want to include such as going into a Follow mode when navigation starts. Please note the sample code does not contain error checking or cleanup

private static final double FOLLOW_MODE_TILT_VALUE_DEGREES = 50;
private static final double CENTER_ON_USER_ZOOM_LEVEL = 18;
protected synchronized void enterFollowMode() {
    locationPresenter = new MyLocationPresenter(mapView, mapboxMap, null);
    locationPresenter.setInitialZoomLevel(CENTER_ON_USER_ZOOM_LEVEL);
    locationPresenter.setFollowCameraAngle(FOLLOW_MODE_TILT_VALUE_DEGREES);
    locationPresenter.setLockNorthUp(false);
    locationPresenter.setFollow(true);
    locationPresenter.onStart();
}

Updating the Progress when using the MapQuest Navigation SDK

When using the Location Layer plugin with the MapQuest Navigation SDK, you may want to make a few adjustments to improve its behavior. The Navigation SDK provides a snapped location which snaps the user's location to the route, balancing out the usual GPS float that a mobile device has.

The first difference when using the Navigation SDK with MapQuest Map SDK is that you'll want to pass a null to the MyLocationPresenter initializer's LocationEngine parameter. Next on the onLocationObservationReceived callback from the NavSDK, you'll want to call forceLocationUpdate and pass in the snapped location.

@Override
public void onLocationObservationReceived(@NonNull LocationObservation locationObservation) {
    locationLayerPlugin.forceLocationUpdate(LocationUtil.mapquestToAndroidLocation(locationObservation.getSnappedLocation()));
}

Customizing the Location Marker

The MyLocationPresenter class lets you choose from three different user location markers or apply your own custom style. The three built-in location markers are NORMAL, COMPASS, and GPS.

The plugin allows for several customizations such as drawables, opacities, and more by passing in a style using the provided applyStyle() API.