Reputation: 15
For a given start and end point of a route, I want to know at which point on the route I will be after a certain amount of time. E.g. given coordinates long_start, lat_start and long_end, lat_end, and taking the route that OSRM suggests, where will the car be after 2 minutes?
Is there a simple way to do this via the OSRM HTTP-API?
Upvotes: 1
Views: 306
Reputation: 947
You can pass the option annotations=duration&overview=full
to the route
service and then use the routes[0].legs[0].annotations.durations
array to find out at which coordinate you would be after a given time.
Pseudo-code:
sum = 0
index = 0
durations = routes[0].legs[0].annotations.durations
while index < durations.length and sum < max_duration
sum += durations[index]
index++
location = decodePolyline(routes[0].geometry)[index]
Upvotes: 3