Nieuw lid |
|
Hallo,
Als ik de volgende functie uitvoer dan berekent de google maps api de route van A naar B met eventuele tussen stops. De locatie van de tussen stops worden uit het bestand xml.xml gehaald.
Het probleem is echter; als het xml bestand meerdere locaties van tussen stops bevat het script wel alle locaties doorloopt maar uiteindelijk alleen de laatste tussenstop gebruikt om de route mee te berekenen.
Is er een oplossing waardoor het google maps wel alle tussenstops gebruikt?
Alvast bedankt voor jullie hulp.
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script type="text/javascript">
window.onload = function(){
load();
}
</script>
<script type="text/javascript">
var directionDisplay;
var directionsService = new google.maps.DirectionsService();
var map;
function load() {
directionsDisplay = new google.maps.DirectionsRenderer();
var dc = new google.maps.LatLng(51.00000, 6.00000);
var myOptions = {
zoom: 13,
mapTypeId: google.maps.MapTypeId.ROADMAP,
center: dc
}
map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
directionsDisplay.setMap(map);
// Change this depending on the name of your PHP file
downloadUrl("xml.xml", function(data) {
var xml = data.responseXML;
var markers = xml.documentElement.getElementsByTagName("marker");
for (var i = 0; i < markers.length; i++) {
var start = "Amsterdam";
var end = "Rotterdam";
var point = new google.maps.LatLng(
parseFloat(markers[i].getAttribute("lat")),
parseFloat(markers[i].getAttribute("lng")));
var waypts = [{
location: point,
stopover: true
}];
calcRoute(start, end, waypts);
}
});
}
function calcRoute(start, end, waypts) {
var request = {
origin: start,
destination: end,
waypoints: waypts,
travelMode: google.maps.DirectionsTravelMode.DRIVING
};
directionsService.route(request, function(response, status) {
if (status == google.maps.DirectionsStatus.OK) {
directionsDisplay.setDirections(response);
}
});
}
function downloadUrl(url, callback) {
var request = window.ActiveXObject ?
new ActiveXObject('Microsoft.XMLHTTP') :
new XMLHttpRequest;
request.onreadystatechange = function() {
if (request.readyState == 4) {
request.onreadystatechange = doNothing;
callback(request, request.status);
}
};
request.open('GET', url, true);
request.send(null);
}
function doNothing() {}
</script>
<div id="map_canvas" style="width: 600px; height: 500px"></div>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script> <script type="text/javascript"> window.onload = function(){ load(); } </script> <script type="text/javascript"> var directionDisplay; var directionsService = new google.maps.DirectionsService(); var map; function load() { directionsDisplay = new google.maps.DirectionsRenderer(); var dc = new google.maps.LatLng(51.00000, 6.00000); var myOptions = { zoom: 13, mapTypeId: google.maps.MapTypeId.ROADMAP, center: dc } map = new google.maps.Map(document.getElementById("map_canvas"), myOptions); directionsDisplay.setMap(map); // Change this depending on the name of your PHP file downloadUrl("xml.xml", function(data) { var xml = data.responseXML; var markers = xml.documentElement.getElementsByTagName("marker"); for (var i = 0; i < markers.length; i++) { var start = "Amsterdam"; var end = "Rotterdam"; var point = new google.maps.LatLng( parseFloat(markers[i].getAttribute("lat")), parseFloat(markers[i].getAttribute("lng"))); var waypts = [{ location: point, stopover: true }]; calcRoute(start, end, waypts); } }); } function calcRoute(start, end, waypts) { var request = { origin: start, destination: end, waypoints: waypts, travelMode: google.maps.DirectionsTravelMode.DRIVING }; directionsService.route(request, function(response, status) { if (status == google.maps.DirectionsStatus.OK) { directionsDisplay.setDirections(response); } }); } function downloadUrl(url, callback) { var request = window.ActiveXObject ? new ActiveXObject('Microsoft.XMLHTTP') : new XMLHttpRequest; request.onreadystatechange = function() { if (request.readyState == 4) { request.onreadystatechange = doNothing; callback(request, request.status); } }; request.open('GET', url, true); request.send(null); } function doNothing() {} </script> <div id="map_canvas" style="width: 600px; height: 500px"></div>
|