开发者

How save the DirectionsResult object in Google Maps [duplicate]

This question already has answers here: Google maps saving draggable directions (2 answers) Closed 4 years ago.

I want to be able to plot a route in Google Maps, modify that route by dragging it, save the changes and reload it at some later time and edit it further. In the sam开发者_如何学Ce manner as Google's MyMap. Simply saving the origin and destination locations wont work as it wont reload the same route.

I can save all of the points in the via_waypoint[] array. This allows me to redraw the route as a polyline but it is no longer editable.

The documentation says that the DirectionsResult is returned in JSON format. So I've tried to convert the DirectionsResult to a JSON string, save and reload that string as a JSON object and pass it to the DirectionsRenderer. But it doesn't display and no errors are thrown.

Below is a sample of what I was trying to do. I've skipped the saving to the database step. I convert the DirectionsResult to a string and then back to a JSON object.

   directionsService.route(request, function(response, status) {
     if (status == google.maps.DirectionsStatus.OK) {
       var str = JSON.stringify(response))
       var obj= JSON.parse(str)
       directionsDisplay.setDirections(obj);
     }

Any help would be gratefully appreciated.

Thanks


Why not save the coordinates of the waypoint[] array and reintroduce them to the a DirectionsRequest object's waypoints member? Later on, when you reload the page, make a request to the DirectionsService as usual, but with the previously mentioned DirectionsRequest object. It should be draggable if you set draggable to true in the DirectionsRendererOptions of your renderer.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜