javascript - google maps v3 waypoints -
im using following code show directions , waypoints waypoints not showing, if use waypoints: [{location: "(39.424504, -76.596594)", stopover: true}]
show waypoint, cant make work array.
i have used alert(waypts[0].location);
, array gets values.
var start = document.getelementbyid('start_cord').value; var end = document.getelementbyid('end_cord').value; var waypts = []; makerequest('get_waypoint.php', function(data) { var data = json.parse(data.responsetext); var latit; var longi; (var = 0; < data.length; i++) { latit = parsefloat(data[i].lat); longi = parsefloat(data[i].lon); waypts.push({location: new google.maps.latlng(latit, longi), stopover: true}); } }); var request = { origin: start, destination: end, waypoints: waypts, optimizewaypoints: true, travelmode: google.maps.travelmode.driving }; directionsservice.route(request, function(response, status) { if (status == google.maps.directionsstatus.ok) { directionsdisplay.setdirections(response); var route = response.routes[0]; var summarypanel = document.getelementbyid('directions_panel'); summarypanel.innerhtml = ''; // each route, display summary information. (var = 0; < route.legs.length; i++) { var routesegment = + 1; summarypanel.innerhtml += '<b>route segment: ' + routesegment + '</b><br>'; summarypanel.innerhtml += route.legs[i].start_address + ' --- '; summarypanel.innerhtml += route.legs[i].end_address + '<br>'; summarypanel.innerhtml += route.legs[i].distance.text + '<br><br>'; } summarypanel.style.display = 'block'; } });
makerequest:
function makerequest(url, callback) { var request; if (window.xmlhttprequest) { request = new xmlhttprequest(); // ie7+, firefox, chrome, opera, safari } else { request = new activexobject("microsoft.xmlhttp"); // ie6, ie5 } request.onreadystatechange = function() { if (request.readystate == 4 && request.status == 200) { callback(request); } } request.open("get", url, true); request.send(); }
Comments
Post a Comment