Search code examples
androidskmaps

Heading mode Rotating Map


I'm using SKMaps v3.0 SDK for Android and I try to change the user Heading mode into Rotating_Map in order to let the user able to rotate map with heading position.

Here is my code :

    private void followTheUserWithHeading(int transitionTime){
    mapView.getMapSettings().setCurrentPositionShown(true);
    mapView.getMapSettings().setFollowPositions(true);
    mapView.getMapSettings().setHeadingMode(SKMapSettings.SKHeadingMode.ROTATING_MAP);
    mapView.animateToBearing(1.0f,true,transitionTime);
    mapView.centerOnCurrentPosition(17,true,500);
}

With followTheUserWithHeading() being called in onRouteCalculationCompleted method.

Unfortunately, the map does not rotate with mobile phone orientation.

N.B. : the user cone is visible, which is not the case when using SKHeadingMode.ROUTE. So it seems my code is not completely crap ... I also tried ROTATING_HEADING but not better.

Thank you very much :)


Solution

  • Okay, I finally found a solution to my problem ...

    This was not a matter of pedestrian mode. In order to make the ROTATIN_MAP works, you have to implement all sensor event.

    See in Android demo project for further details, but here is look to code snippet

     private void setHeading(boolean enabled) {
        if (enabled) {
            headingOn = true;
            mapView.getMapSettings().setHeadingMode(SKHeadingMode.ROTATING_MAP);
            startOrientationSensor();
        } else {
            headingOn = false;
            mapView.getMapSettings().setHeadingMode(SKMapSettings.SKHeadingMode.NONE);
            stopOrientationSensor();
        }
    }
    
    /**
     * Activates the orientation sensor
     */
    private void startOrientationSensor() {
        orientationValues = new float[3];
        SensorManager sensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);
        Sensor orientationSensor = sensorManager.getDefaultSensor(Sensor.TYPE_ORIENTATION);
        sensorManager.registerListener(this, orientationSensor, SensorManager.SENSOR_DELAY_UI);
    }
    
    /**
     * Deactivates the orientation sensor
     */
    private void stopOrientationSensor() {
        orientationValues = null;
        SensorManager sensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);
        sensorManager.unregisterListener(this);
    }