I'm trying to implement some kind of personal tracker for real-time tracking, and I am stuck with this problem: let's say that point A is my origin, and point E is my destination. Points B, C, and D are waypoints that define a specific route for the bus. Every 15 seconds I get an updated bus location, and then I need to show the user the approximate time remaining before reaching it, based on its route.
In the Google Directions API, each breakpoint is taken into account without considering the current bus position within the specified route. In fact, if I, for example, get the past point C, then points A, B and C cannot be calculated, because the buses have already stopped at these points.
How can I achieve something like this using the GMaps API? Is it possible?
EDIT: If that helps, I do it on the Node.js server and I cannot control the location update interval. This is because I am making an external API call that returns me the location of the specified bus. Of course, I can call how many times I want, but the returned location is updated every 15 seconds. There is also a call that returns me all the lat / lon coordinates that make up the route, to use them as waypoint parameters for Google Directions.
I see that, knowing the start and end points of the route and knowing the current bus position on the route, I can determine which waypoints I should consider when I call the Google Directions API the next time. But how can I determine if the bus is inside the route? And how can I determine its "progress" within the route? I cannot find an obvious way to do this.
UPDATE:
So, I followed the Loreda L answer and checked if I could use the Google Distance Matrix API instead of Google Directions. But I still could not solve it. For example, let me use this call example:
https:
Here I have a beginning lat = -23.307339
and lon = -51.171461
, but let's say that the tire has advanced on the route in such a way that it now occupies the position: lat = -23.315229; lon = -51.170670
that is halfway between two points on this route. Then let me call again:
https:
, . , . , . Google:
https://www.google.com.br/maps/dir/'-23.307339,-51.171461'/Condom%C3%ADnio+Comercial+Paula+Center,+Rua+Borba+Gato,+1170+-+Jd+Am%C3%A9rica,+Londrina+-+PR,+86010-630/@-23.3191734,-51.1753824,14.75z/data=!4m22!4m21!1m13!2m2!1d-51.171461!2d-23.307339!3m4!1m2!1d-51.1655654!2d-23.3066109!3s0x94eb44a453d12405:0x4fe6589ceb2a7640!3m4!1m2!1d-51.1679874!2d-23.3121241!3s0x94eb44a7b0b222bd:0xebae4eed90aa817!1m5!1m1!1s0x94eb436e990ab02f:0xbea600ba72575bee!2m2!1d-51.1606428!2d-23.324045!3e0
, Google Directions:
https:
, , .