0
votes

I am working on an app in which I have to show shortest route. I am using Google Direction API but the result is different from Google Maps app for same destination and travel mode.

https://maps.googleapis.com/maps/api/directions/json?origin=19.107163,72.862375&destination=19.106995400000002,72.8643029&sensor=false&mode=driving&alternatives=true&key=XXXXXXXXXXXXXXXXXX

Since alternative is true I am already using shortest route from available routes (response).

Note : - When I enter lat lng of origin and destination in the map app it shows same result. It shows different result only when we type the origin and destination.

enter image description here

enter image description here

1
Maybe one of the apps has different settings active, such as avoiding highways and tolls, or traffic? Check the settings or log out of your google account and see if that helps?Aamir
The destination is 5 mins away from my location. There is no tolls and highways. Regarding traffic I am already using shortest route from response.Shahbaz Hashmi

1 Answers

2
votes

I got the solution. When I put destination place_id instead of lat lng it is showing same result as google map app. I don't know how it is working. Such variation not even mentioned in developer docs.

https://maps.googleapis.com/maps/api/directions/json?origin=19.107163,72.862375&destination=place_id:ChIJ_0P9DzjI5zsRf5xuhTv8VCk&sensor=false&mode=driving&alternatives=true&key=XXXXXXXXXXXXXXXXXXXXXX