1

I need to show a route from point A to point B on my android app using google maps. Currently my app just showing distance and travel time from DistanceMatrix API. Now I want to visually show the whole route on the map.

The question is should I use both DistanceMatrix for calculating distance/travel time AND Directions API for getting the route details to show? Or maybe Directions API is enough for both tasks? I have read some articles (i.e. Why Google direction and distance matrix API show different results for source and destination value) that both APIs return different distance results...

Marcin
  • 1,113
  • 1
  • 11
  • 33
  • Direction API is exactly what you need. It can also give multiple routes and you can select the route according to distance or duration. But still there is little difference with Google Maps App. But I have figured it out. See my post https://stackoverflow.com/a/54286190/4685284 – Shahbaz Hashmi Jan 22 '19 at 08:56

1 Answers1

1

Directions API does return all of the information from DistanceMatrix API, plus the directions.

I was able to drill down to the distance information like this:

const distance = payload?.body?.routes[0]?.legs[0]?.distance;
const duration = payload?.body?.routes[0]?.legs[0]?.duration;

_Note: Be careful as

Jim
  • 3,821
  • 1
  • 28
  • 60