Hi everybody! I've been trying to implement a map which has multiple routes and shows them at the same time. It seems that when the xml gets read, the only info left is the last entry. This causes that the only route rendered is the last one. I would be very grateful if you could give me a hand with this problem.
The code I wrote is the following: <script type="text/javascript" src="http://maps.google.com/maps/api/js? sensor=false"></script> <script type="text/javascript" src="scripts/downloadxml.js"></script> <script type="text/javascript"> var directionsDisplay; var directionsService = new google.maps.DirectionsService(); var map; // function to calculate the route function calcRoute(point1,point2) { var request = { origin:point1, destination:point2, //waypoints: mrutas, travelMode: google.maps.DirectionsTravelMode.DRIVING }; directionsService.route(request, function(response, status) { if (status == google.maps.DirectionsStatus.OK) { directionsDisplay.setDirections(response); }else{echo="error"} }); } function initialize() { // this makes the map directionsDisplay = new google.maps.DirectionsRenderer(); var myOptions = { zoom:6, center: new google.maps.LatLng(40.371659, -3.62548), mapTypeControl: true, mapTypeControlOptions: {style: google.maps.MapTypeControlStyle.DROPDOWN_MENU}, navigationControl: true, mapTypeId: google.maps.MapTypeId.HYBRID, } map = new google.maps.Map(document.getElementById("rutas"), myOptions); directionsDisplay.setMap(map); // reads the data from the xml downloadUrl("rutas01.xml", function(doc) { var xmlDoc = xmlParse(doc); var rutas = xmlDoc.documentElement.getElementsByTagName("ruta"); for (var i = 0; i < rutas.length; i++) { // gets atributes for start point var point1 = new google.maps.LatLng( parseFloat(rutas[i].getAttribute("lat1")), parseFloat(rutas[i].getAttribute("lng1"))); // gets atributes endt point var point2 = new google.maps.LatLng( parseFloat(rutas[i].getAttribute("lat2")), parseFloat(rutas[i].getAttribute("lng2"))); // gets atributes for info window (not implemented yet) var html = rutas[i].getAttribute("html"); // gets atributes for label (not implemented yet) var label = rutas[i].getAttribute("label"); // calculates the route var cruta = calcRoute(point1,point2); } }); } DATA IN THE XML <rutas> <ruta html="data to show in the infowindow Valencia Madrid" label="Sitio 1" lat1="39.470239" lng1="-0.376805" lat2="40.416691" lng2="-3.700345" /> <ruta html="data to show in the infowindow Sevilla Valencia" label="Sitio 2" lat1="37.38264" lng1="-5.996295" lat2="39.470239" lng2="-0.376805" /> <ruta html="data to show in the infowindow Madrid Sevilla" label="Sitio 3" lat1="40.416691" lng1="-3.700345" lat2="37.38264" lng2="-5.996295" /> </rutas> The online html http://espanavision.es/web/mapas/recogida.html Thank you in advance, best regards Jose C Lopez -- You received this message because you are subscribed to the Google Groups "Google Maps JavaScript API v3" group. To post to this group, send email to google-maps-js-api...@googlegroups.com. To unsubscribe from this group, send email to google-maps-js-api-v3+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/google-maps-js-api-v3?hl=en.