Search in sources :

Example 1 with CompassListener

use of com.mapbox.mapboxsdk.plugins.locationlayer.CompassListener in project mapbox-plugins-android by mapbox.

the class CompassListenerActivity method onMapReady.

@Override
public void onMapReady(final MapboxMap mapboxMap) {
    LocationEngine locationEngine = new LocationEngineProvider(this).obtainBestLocationEngineAvailable();
    locationLayerPlugin = new LocationLayerPlugin(mapView, mapboxMap, locationEngine);
    locationLayerPlugin.setRenderMode(RenderMode.COMPASS);
    locationLayerPlugin.addCompassListener(new CompassListener() {

        @Override
        public void onCompassChanged(float userHeading) {
            CameraPosition cameraPosition = new CameraPosition.Builder().bearing(userHeading).build();
            mapboxMap.easeCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
        }

        @Override
        public void onCompassAccuracyChange(int compassStatus) {
            Timber.v("Compass reading: %d", compassStatus);
        }
    });
}
Also used : LocationEngine(com.mapbox.android.core.location.LocationEngine) LocationLayerPlugin(com.mapbox.mapboxsdk.plugins.locationlayer.LocationLayerPlugin) CameraPosition(com.mapbox.mapboxsdk.camera.CameraPosition) CompassListener(com.mapbox.mapboxsdk.plugins.locationlayer.CompassListener) LocationEngineProvider(com.mapbox.android.core.location.LocationEngineProvider)

Aggregations

LocationEngine (com.mapbox.android.core.location.LocationEngine)1 LocationEngineProvider (com.mapbox.android.core.location.LocationEngineProvider)1 CameraPosition (com.mapbox.mapboxsdk.camera.CameraPosition)1 CompassListener (com.mapbox.mapboxsdk.plugins.locationlayer.CompassListener)1 LocationLayerPlugin (com.mapbox.mapboxsdk.plugins.locationlayer.LocationLayerPlugin)1