Fatih Aktepe
Fatih Aktepe

Reputation: 601

How to get distance to waypoint in Navigation Manager

In my android app I'm using Here map SDK for navigation. I have multiple waypoints in my route when user is navigating. I would like to receive distance to next waypoint while user navigates in the app. Currently you can get NavigationManager.getInstance().getDestinationDistance() this function returns the remaining distance to the end point of the route. How can I get remaining distance for each waypoint?

Upvotes: 0

Views: 919

Answers (2)

sound
sound

Reputation: 1999

To complete what @Blake already said (can be useful for others),

getNextManeuverDistance() will only give you the distance to the next Maneuver from the Previous one.

If you want the actual distance from your position, in your Position listener you need to calculate it based on the geoPosition of the next Maneuver and your actual geo position :

maneuver.getCoordinate().distanceTo(geoPosition.getCoordinate()) 

So your code will be like this for example :

 @Override
 public void onPositionUpdated(GeoPosition geoPosition) {
        Maneuver maneuver = NavigationManager.getInstance().getNextManeuver();
        if (maneuver != null) {
            Log.i(TAG, "OnPositionUpdatedEvent : " + maneuver.getAction().name()
                    + " turn : " + maneuver.getTurn()
                    + " in " +  maneuver.getCoordinate().distanceTo(geoPosition.getCoordinate()));

        }
    }

Upvotes: 1

Blake
Blake

Reputation: 43

As the users position changes you can determine the distance to the next waypoint (next maneuver in route).

// listen for positioning events
private PositioningManager.OnPositionChangedListener mapPositionHandler = new PositioningManager.OnPositionChangedListener()
{
    @Override
    public void onPositionUpdated(PositioningManager.LocationMethod method, GeoPosition position, boolean isMapMatched) {
    ...
    ...
    //Code you want
    long meters = NavigationManager.getInstance().getNextManeuverDistance();
    }

Upvotes: 0

Related Questions