-function post_data(url, data) {
- /* Create a new form, and add it to the DOM. Then, create a hidden
- input control as a child of the form which contains the data that
- we'd like to post. Finally, add the form to the document's body,
- and submit it. */
- var new_form = document.createElement("form");
- new_form.method = "post";
- new_form.action = url;
- var new_input = document.createElement("input");
- new_input.setAttribute("id", "data");
- new_input.setAttribute("name", "data");
- new_input.setAttribute("type", "hidden");
- new_input.setAttribute("value", data);
- new_form.appendChild(new_input);
- document.body.appendChild(new_form);
- new_form.submit();
-}
-
-
var producers = new Array();
var consumers = new Array();
+var postback_url = "${c.postback_url}";
+
/* The URL encoding changes all of our double quotes to ", so we
* have to convert them back before we do anything with the JSON
* data. */
if (status == google.maps.DirectionsStatus.OK) {
json_string += JSON.stringify(result);
- for (var trip_idx = 0; trip_idx < result.trips.length; trip_idx++) {
- num_routes = result.trips[trip_idx].routes.length;
- if (num_routes > 1) {
- alert("Unexpected number of routes (" +
- result.trips.routes.length.toString() +
- ") on trip number " + trip_idx.toString() + '.');
+ for (var route_idx = 0; route_idx < result.routes.length; route_idx++) {
+ var num_legs = result.routes[route_idx].legs.length;
+ if (num_legs > 1) {
+ alert("Unexpected number of legs (" +
+ result.routes.legs.length.toString() +
+ ") on route number " + route_idx.toString() + '.');
}
}
}
if (completed_requests == total_requests) {
// Close the array, and do something with the result.
json_string += ']';
- post_data('/directions/json_to_kml', json_string)
+ var F = new Form();
+ F.post_data(postback_url, json_string);
}
else {
// Continue the array.
continue;
}
- var producer_latlng = new google.maps.LatLng(producers[i].latitude,
- producers[i].longitude);
-
- var consumer_latlng = new google.maps.LatLng(consumers[i].latitude,
- consumers[i].longitude);
+ /* We'll pass these to the DirectionsRequest object. They aren't
+ * necessarily LatLngs, since if either the latitude or
+ * longitude is missing, we'll fall back to using the name. */
+ var producer_latlng;
+ var consumer_latlng;
+ if (producers[i].latitude && producers[i].longitude) {
+ producer_latlng = new google.maps.LatLng(producers[i].latitude,
+ producers[i].longitude);
+ }
+ else {
+ producer_latlng = producers[i].name;
+ }
+
+ if (consumers[j].latitude && consumers[j].longitude) {
+ consumer_latlng = new google.maps.LatLng(consumers[j].latitude,
+ consumers[j].longitude);
+ }
+ else {
+ consumer_latlng = consumers[j].name;
+ }
+
var directions_request = {
origin: producer_latlng,
destination: consumer_latlng,
- provideTripAlternatives: true,
-
+ provideRouteAlternatives: true,
travelMode: google.maps.DirectionsTravelMode.DRIVING
}