Google Directions API返回0条路线 [英] Google Directions Api returning 0 routes

查看:123
本文介绍了Google Directions API返回0条路线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在调用google路线api来计算往返行程值。一般来说,它完美的作品。然而,我遇到了一个没有提出任何路线的用例。然而,当我们使用js google.maps.DirectionsService版本具有相同的出发地,目的地,航点和travelMode时,它可以正常工作。



失败的调用为:



官方文件也证实了这一点: 通过:前缀以避免中途停留导致对他们的解释非常严格的方向 航点。如果Google Maps Directions API无法通过该点创建路线,则可能会导致路线严重弯路或在响应状态代码中出现ZERO_RESULTS


https://developers.google.com/maps/documentation/方向/介绍#航点



我希望这能解释您的疑问!


We are calling the google directions api to calculate round trip values. In general it works perfectly. I have however come across a use case where it fails to come up with any route. However when we use the js google.maps.DirectionsService version with the same origin, destination, waypoints, and travelMode it works.

The failing call is: https://maps.googleapis.com/maps/api/directions/json?origin=-33.92873,18.458879&destination=-33.92873,18.458879&waypoints=via:-33.9403,18.666731&mode=driving&key=

The response is

{
   "geocoded_waypoints" : [ {}, {}, {} ],
   "routes" : [],
   "status" : "ZERO_RESULTS"
}

解决方案

When you use via: prefix (no stopover), it adds some additional restrictions. Particularly the U-turn maneuver is not allowed, the route must go straight forward through waypoint. If this is impossible the Directions service will return ZERO_RESULTS.

To check this hypothesis I created exactly the same request, but with stopover (without via: prefix). You can see the result in the Directions calculator:

https://directionsdebug.firebaseapp.com/?origin=-33.92873%2C18.458879&destination=-33.92873%2C18.458879&waypoints=-33.9403%2C18.666731

Indeed, you should do the U-Turn in -33.9403,18.666731 (marker B) and this is the reason for ZERO_RESULTS when you try to create a route without stopovers.

This is also confirmed in the official documentation:

Caution: Using the via: prefix to avoid stopovers results in directions that are very strict in their interpretation of the waypoint. This may result in severe detours on the route or ZERO_RESULTS in the response status code if the Google Maps Directions API is unable to create directions through that point.

https://developers.google.com/maps/documentation/directions/intro#Waypoints

I hope this explains your doubt!

这篇关于Google Directions API返回0条路线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆