简体   繁体   中英

How to Show path from source and destination in Android app and Navigate the user within the App

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

@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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM