Google Map Direction API Return Zero Results Swift

China☆狼群 提交于 2020-01-06 20:16:31

问题


My App using Google Maps Direction API to draw route between any two positions (origin - direction positions)user pin it.

I used the API like this way:

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

The problem is sometimes the response return Zero Results, like this :

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

  "routes": [],

  "status": "ZERO_RESULTS"
}

I searched a lot but no useful results.

Anyone faced this problem?

Could this problem be because I used the free API?

I will be thankful for any help.

Thanks.


回答1:


If there will be no path then it returns the same.

See this link : Path Information

Hope this helps!

UPDATE:

Try to covert latitude-longitude into address and pass it over the URL and it will solve the issue. CLGeocoder might help you to do the same.




回答2:


It's because of wrong lat-long for the destination. Also path is not available for the requested Travel mode.




回答3:


Try with this google API:

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

Pass latitude, longitudes to above API. You will get the result.



来源:https://stackoverflow.com/questions/37786919/google-map-direction-api-return-zero-results-swift

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!