I\'m making an app with the Directions API to create biking directions. The user needs to be able to start from a custom point, add custom stopping points along the route, a
I was trying for saving waypoints and this should be useful to other users who are searching for the same.
I have created set of scripts to save the directions waypoints in the database also code to fetch that information back and display the waypoints in another map. I have provided html, php and sql files and complete explanation in this link.
http://vikku.info/programming/google-maps-v3/draggable-directions/saving-draggable-directions-saving-waypoints-google-directions-google-maps-v3.htm.
Also you can copy the source code of that page and you can edit according to your preference and use the sql file for the database.
UPDATE: I've found my own answer.
The object that houses the most current map data is directionsDisplay.directions
. That object holds the data from the map AS SHOWN…including the via_waypoints[]
array, which shows up as a child of the legs[]
array.
The code below shows how you can print the string for your analyzing pleasure (I've made this function to be called by a button on the HTML side):
//GET THE JSON Object
var newString = JSON.stringify(directionsDisplay.directions);
//set up area to place drop directionsResponse object string
var directions_response_panel = document.getElementById("directions_response");
//dump any contents in directions_response_panel
directions_response_panel.innerHTML = "";
//add JSON string to it
directions_response_panel.innerHTML = "<pre>" + newString + "</pre>";
Lesson of the night: directionsDisplay.directions
calls on the map data AFTER a user has made dragable changes to their directions.