本文介绍了Google Direction API和Google Maps App显示针对同一目的地的不同路线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个必须显示最短路径的应用程序.我使用的是Google Direction API,但在相同的目的地和出行方式下,结果却与Google Maps应用不同.

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.

推荐答案

我找到了解决方案.当我放置目标place_id而不是lat lng时,它显示的结果与google map应用程序相同.我不知道它是如何工作的.这样的变化甚至在开发人员文档中都没有提及.

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= ; alternatives = true& key = XXXXXXXXXXXXXXXXXXXXXX

这篇关于Google Direction API和Google Maps App显示针对同一目的地的不同路线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-27 08:16