Google 地图方向 API Return 零结果 Swift

Google Map Direction API Return Zero Results Swift

我的应用程序使用 Google 地图 方向 API 在任意两个位置(原点 - 方向位置)之间绘制路线,用户将其固定。

我是这样使用API的:

https://maps.googleapis.com/maps/api/directions/json?origin=(fromLat),(fromLng)&destination=(toLat),(toLng)&mode=(travelMode)&departure_time=now&alternatives=true&language=(lang)

问题有时是响应 return 零结果,像这样:

{
  "geocoded_waypoints": [
    {},
    {}
  ],

  "routes": [],

  "status": "ZERO_RESULTS"
}

我搜索了很多但没有有用的结果。

有人遇到过这个问题吗?

会不会是因为我用了免费的API?

如有任何帮助,我将不胜感激。

谢谢。

这是因为目的地的经纬度错误。路径也不适用于请求的旅行模式。

试试这个 google API:

https://maps.google.com/maps?saddr=%@,%@&daddr=%@,%@

将纬度、经度传递给上面API。你会得到结果。

如果没有路径则returns相同。

看到这个 link : Path Information

希望对您有所帮助!

更新:

尝试将经纬度转换为地址并将其传递给 URL,这将解决问题。 CLGeocoder 可能会帮助你做同样的事情。

结果为零,因为问题出在 API。通过 方向 API here 的 google 地图文档使用正确的 API。请避免使用堆栈溢出中提供的 api,因为它们已过时。

祝你好运!