Is there any smart way (algorithm, API, etc) where I can estimate the time of arrival between two geolocations and these geolocations are nothing but two people trying to reach each other on the map?
-
1Possible duplicate of [Android - How to get estimated drive time from one place to another?](https://stackoverflow.com/questions/8410787/android-how-to-get-estimated-drive-time-from-one-place-to-another) – Murmel Nov 20 '17 at 13:30
3 Answers
Google Maps Directions Api provides a way for you to get the estimated travel time for a trip between two points, so if you know both users locations you could utilize that.
for example if you send https://maps.googleapis.com/maps/api/directions/json?origin=NewYork&destination=LosAngeles&mode=walking part of the response will include
duration: {
text: "37 days 23 hours",
value: 3278737
}
Implementation details depend on how your application works, but the api could certainly be a starting point.

- 843
- 1
- 7
- 11
There is no direct solution to your problem.
However google provides the google direction api. This api gives you ability to calculate the distance from one location to another and also gives you estimated time but with these limitations-
- This is static not dynamic. so you can't really calculate the moving persons you have to provide two locations and this will give distance from that two locations.
- This gives distance which follows the road. so you cant really define your own path . the google direction api will give distance for the road to travel.
- the time is average time to travel . it does not take the speed you are traveling into account.
So to achieve what you want you will have to do many things by yourself. main the calculation.
The api which you require is navigation api . but unfortunately this is not provided by google for public use.
Hope this answer helps you.

- 2,138
- 2
- 19
- 52
As already described by RJ Aylward, you can use Google's directions API to estimate the time needed to get from one place to another taking directions and traffic into account. But you don't have to use the web API and build your own wrapper, instead use the Java implementation provided by Google itself, which is available through the Maven/gradle repository.
Add the google-maps-services to your app's build.gradle:
dependencies { compile 'com.google.maps:google-maps-services:0.2.5' }
Perform the request and extract the duration:
// - Put your api key (https://developers.google.com/maps/documentation/directions/get-api-key) here: private static final String API_KEY = "AZ.." /** Use Google's directions api to calculate the estimated time needed to drive from origin to destination by car. @param origin The address/coordinates of the origin (see {@link DirectionsApiRequest#origin(String)} for more information on how to format the input) @param destination The address/coordinates of the destination (see {@link DirectionsApiRequest#destination(String)} for more information on how to format the input) @return The estimated time needed to travel human-friendly formatted */ public String getDurationForRoute(String origin, String destination) // - We need a context to access the API GeoApiContext geoApiContext = new GeoApiContext.Builder() .apiKey(apiKey) .build(); // - Perform the actual request DirectionsResult directionsResult = DirectionsApi.newRequest(geoApiContext) .mode(TravelMode.DRIVING) .origin(origin) .destination(destination) .await(); // - Parse the result DirectionsRoute route = directionsResult.routes[0]; DirectionsLeg leg = route.legs[0]; Duration duration = leg.duration; return duration.humanReadable; }
For simplicity, this code does not handle exceptions, error cases (e.g. no route found -> routes.length == 0), nor does it bother with more than one route or leg. Origin and destination could also be set directly as LatLng
instances (see DirectionsApiRequest#origin(LatLng)
and DirectionsApiRequest#destination(LatLng)
.
Further reading: android.jlelse.eu - Google Maps Directions API
This is an answer I already give at Android - How to get estimated drive time from one place to another?

- 5,402
- 47
- 53