Question

I'm developing an android app for my college that helps students track the current location of the college bus and also give them an estimated time when the bus might reach them. As of now I get the current location of the bus(via a device present on the bus) and the location of the student. I'm stuck at the point where I have to find the distance between the two GPS co-ordinates. I have to find the distance between the bus and the student "along a specific route" (i.e the path the bus takes). Using Google Map APIs will not always give the distance along the route I want. How do I find the distance between two points along a specific route?

Was it helpful?

Solution 2

I would it solve this way:

1) The direct line of sight distance betweent two GPS points is simple, simply use Location.distanceBetween() method, you will find hundres of posts here on SO.

2) The length of the route. This part is more difficult. If you are not happy with the result of google: Store your bus routes as rough sequence of lat/lon coordinates (a poly line). A point per street corner should be sufficient. Then find the nearest point on the route, a simple brute force search should be sufficent for your task. Then simply iterate from found route point till destination point, and sum up using the distanceBetween() method.

OTHER TIPS

The Google Maps Android API Utility Library has a range of applications useful for your case, including calculating distance between two points, by using the computeDistanceBetween(LatLng from, LatLng to) method from the SphericalUtil class.

Also check this link.

Google Distance Matrix API provides travel distance and time for a matrix of origins and destinations.

Or you could try Google Directions API.

Also, I believe this guy had the same doubt of yours.

Hope this helps you.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top