1

Rather than using the default location engine, I have a custom solution which provides me location events via a onCustomLocationEvent() callback. Using the Mapbox Android SDK I would like to set the devices current location (ie. the blue-dot) using the values returned from the custom location event. In other words, I would like to set the position of the blue-dot, the radius of the accuracy circle, and the heading of the arrow.

enter image description here

So far, I have successfully done everything except for setting the direction of the arrow. I can create a new CompassEngine and set the heading, but that does not change update the blue-dot UI. Is there some method I am not aware of such as mapboxMap.getLocationComponent().getCompassEngine().setHeading() or is this not possible with Mapbox Android SDK? Thanks!

public void onCustomLocationEvent(double latitude, double longitude, float heading, float bearing, float accuracy) {

    Location location = new Location("customLocation");
    location.setLatitude(latitude);
    location.setLongitude(longitude);
    location.setAccuracy(accuracy);
    // location.setBearing(bearing); has no effect 

    CompassEngine engine = new CompassEngine() {

        @Override
        public void addCompassListener(@NonNull CompassListener compassListener) {

        }

        @Override
        public void removeCompassListener(@NonNull CompassListener compassListener) {

        }

        @Override
        public float getLastHeading() {
            return heading; // does not update the UI
        }

        @Override
        public int getLastAccuracySensorStatus() {
            return 0;
        }
    };

    mapboxMap.getLocationComponent().setCompassEngine(engine);

}

Espresso
  • 740
  • 13
  • 32

0 Answers0