Displaying results of google direction web service without using javascript api

久未见 提交于 2019-11-29 07:22:44

You can do this, but there are several gotchas.

First, make sure your app is compliant with point 10.5.d here: https://developers.google.com/maps/terms#10-license-restrictions

Unlike the JSON response from Directions API web service, which has consistently named fields, the JSON response from the JavaScript Directions service is not for you to parse. Instead, you need to access the DirectionsResult object as a JavaScript object, which contains google.maps.LatLng objects, e.g. routes[0].legs[0].steps[0].start_location

https://developers.google.com/maps/documentation/javascript/directions#DirectionsResults https://developers.google.com/maps/documentation/javascript/directions#Steps

For a route you've gotten from the Directions API web service, there are several ways to display it on the JavaScript API. My preference would be to "translate" the JSON response into a DirectionsResult object. You can do this on your server or in JavaScript, but I think the former is better.

Alternatively, you can re-query the Directions service (using the JavaScript service) to get the route again. Not only will this consume additional quota, it may also return a different (more up-to-date) route. Whether that's good or bad, it depends on what you want.

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