itinero / routing

The routing core of itinero.
Apache License 2.0
221 stars 69 forks source link

Check if user is on route #221

Closed Sonnenspeer closed 5 years ago

Sonnenspeer commented 6 years ago

Hi.

I wanted to check if the users current position is on the route or in the near of that. And if it's not then a new route should be calculated.

My idea was that whenever I get a new GPS point (user position) I try to resolve this position like

var resPoint = new router.Resolve(profile, currentPos.Latitude, currentPos.Longitude, searchDistanceInMeter: 5);

and when this point is null (is it null when no point was resolved in the search distance?) then the user is no more on the given route.

Is this an eligible way of doing it?

xivk commented 6 years ago

There are some methods available for this in the route-extensions:

https://github.com/itinero/routing/blob/develop/src/Itinero/RouteExtensions.cs#L370

This one projects the current location on the route and figures out how far away it is.