3

I have a situation where I would like to estimate where a bus should be between two given points - the origin and the final destination.

The only data I have available is the time that this bus is due at each stop between the origin and the destination.

So using the due time for each stop, I can obviously calculate how many seconds away it is from the given stop.

At this point, I have the map just plotting the bus at each stop once it gets there - so effectively just a list of buses that are at each stop.

What I am wanting to do is get an estimated location of the bus based on the number of seconds away so that I can make it look like these buses are actually moving along the route.

Is there any way to do this sort of thing?

James West
  • 31
  • 1

1 Answers1

1

Use the Google Directions API to calculate a route between bus stops. Hopefully Google's directions will be the same as the actual route the bus is taking. If not, you'll need to determine a different way to represent the route as a set of lat-lng points. Some alternate approaches are:

  1. Use OpenStreetMaps layers, select and label your bus routes, and put them in your own spatial store.
  2. Digitize a bus map and, label, and put the digitized routes in your own spatial store.

If Google Directions API is acceptable, decode the polyline returned in the Google response into a set of lat-lng points. Use bus-stop time and current time to calculate percent of route completed, and use the percentage to choose the closest point in the polyline. Depending on the level of accuracy you want, you can assume same time between each point in the polyline (unrealistic but easy), or calculate the distance between each point in the polyline and choose the one you are closest to at a point in time.

Once you get the correct point in the polyline, use that point to draw your buses on the map.

Community
  • 1
  • 1
lreeder
  • 12,047
  • 2
  • 56
  • 65