Reputation: 273
I'm trying to develop an Android app and I'm able to fetch the destination lat and long from JSON response. I manged to collect the users current lat and long.
Now How can I show a route or Line from source and destination and update the users current location for every few seconds.
Is it possible to do this and show the ETA and distance between the markers?
Thank You
Upvotes: 1
Views: 1476
Reputation: 6791
@Uday, the plotting of polyline and calculating the direction between two locations can be done using Google Maps Directions API.
The Google Maps Directions API is a service that calculates directions between locations using an HTTP request.
In this tutorial, you'll see how to use Google Direction API and Places API. It will also guide you on the implementation of API and Google HTTP Client Library for Java. For the ETA and distance between the markers Google Direction response has an object called Distance and Duration within "LEGS" array:
A DirectionsLeg defines a single leg of a journey from the origin to the destination in the calculated route. For routes that contain no waypoints, the route will consist of a single "leg," but for routes that define one or more waypoints, the route will consist of one or more legs, corresponding to the specific legs of the journey.
distance indicates the total distance covered by this leg, as a Distance object
duration indicates the total duration of this leg, as a Duration object
Here is a related SO question about travel time. It explains how to get the duration of each leg and distance until the end marker point and how to parse the distance and duration in your app.
Upvotes: 2