Я создаю приложение с помощью API Directions для создания велосипедных маршрутов.Пользователь должен иметь возможность начинать с пользовательской точки, добавлять собственные точки остановки вдоль маршрута и фактически перетаскивать направления.Как только они закончат, мне нужно сохранить новый маршрут в базе данных.
У меня есть карта, которая работает, пользователи могут добавлять свои стартовые и путевые точки через поля ввода HTML, и это прекрасно перетаскивается (извините за обильное количество комментариев ... это в первую очередь, чтобы я мог вспомнить, что происходит ...о, и не беспокойтесь в этом разделе о синтаксисе ... Я копирую и вставляю из разных частей, поэтому я мог пропустить "}" ... все функции этого кода):
function initialize() {
var rendererOptions = {
draggable: true,
//end redererOptions
};
directionsDisplay = new google.maps.DirectionsRenderer(rendererOptions);
var chicago = new google.maps.LatLng(42.73352,-84.48383);
var myOptions = {
zoom: 13,
mapTypeId: google.maps.MapTypeId.ROADMAP,
center: chicago,
//end myOptions
}
//create the world of the dream (define where the map's gonna go
map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
//and the subject fills it with it's subconscious (Call the map from Directions and place it in the div we've created)
directionsDisplay.setMap(map);
//tell google where the printed directions will go
directionsDisplay.setPanel(document.getElementById("directions_detail"));
//end initialize()
};
function calcRoute() {
//get start string from Start input box
var start = document.getElementById("start").value;
//get end string from End input box
var end = document.getElementById("end").value;
//set up an array for waypoints
var waypts = [];
//define where the waypoints will come from
var checkboxArray = document.getElementById("waypoints");
//loop to retrieve any waypoints from that box
for (var i = 0; i < checkboxArray.length; i++) {
//if any options in the select box are selected, add them
if (checkboxArray.options[i].selected == true) {
waypts.push({
//set up parameters to push to the Directions API
location:checkboxArray[i].value,
//make them explicit waypoints that separate the route into legs
stopover:true});
//end if loop
}
//call the Directions Service API, pass the request variable (above) and call a function asking for the response and status objects
directionsService.route(request, function(response, status) {
if (status == google.maps.DirectionsStatus.OK)
{
//pass the response object to the map
directionsDisplay.setDirections(response);
//set up a route variable for the upcoming loop
var route = response.routes[0];
//set up a variable for the route summary, define the <div> where this will be presented to the user
var summaryPanel = document.getElementById("directions_panel");
//clear the <div>
summaryPanel.innerHTML = "";
//turn direcitons_panel "on"...gives the div a color (in my css)
summaryPanel.className = "directions_panel_on";
// For each route, display summary information.
for (var i = 0; i < route.legs.length; i++) {
//set up a route segment variable to display a 1-based segment for the segment summary in html
var routeSegment = i + 1;
summaryPanel.innerHTML += "<b>Route Segment: " + routeSegment + "</b><br />";
summaryPanel.innerHTML += route.legs[i].start_address + " to ";
summaryPanel.innerHTML += route.legs[i].end_address + "<br />";
summaryPanel.innerHTML += route.legs[i].distance.text + "<br /><br />";
//end for loop
};
//end directionsService() function
});
//end calcRoute() function
}
SO,У тебя есть моя база.Все работает (у меня это работает на моем сервере)… пользователи могут создать полностью настроенную карту.Я просто не могу сохранить его, если они решили перетащить путь маршрута, потому что мне нужно вызвать объект с помощью AJAX, и единственный объект, который я знаю, как вызвать, связан с переменной request
, которая определяет массив waypointsкак трудные точки остановки, которые разделяют маршрут вверх.
Я знаю, что искомый массив называется via_waypoint[]
внутри массива legs[]
... он просто получает объект из проклятого DirectionsRenderer с заполненным тупым массивом via_waypoints[]
.У меня есть все остальное, готовое перейти на сторону PHP / MySqul и AJAX.
Я уже пробовал этот урок ... и не могу заставить его работать.Основной ответ сам по себе говорит, что он многое упустил, и я настолько новичок в JavaScript, что, похоже, он слишком много для меня пропустил.
[смайлик глаз щенка] Пожалуйста, помогите