Displaying results of google direction web service without using javascript api

后端 未结 1 1827
温柔的废话
温柔的废话 2020-12-18 01:23

I am developing a application which will find direction between 2 points, display it on the google map and store it in server side so that I can render it again when needed

相关标签:
1条回答
  • 2020-12-18 02:26

    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.

    0 讨论(0)
提交回复
热议问题