javascript - Google Maps Direction Service ZERO RESULTS -
i getting 0 results status when make call using google directions service when shouldn't, far can see. have walked through debugger , looks values correct. using directions service route method waypoints. origin, need use lat, lng vals because changing, waypoints , destination, use full address. waypoint addresses don't have country @ end , stops @ state, destination have country value in address. wouldn't think that's problem. addresses in us, in same state.
anybody see wrong code , how causing this, assuming values being filled in correct?
function setroute() { var waypts = ""; var caddress = $("#companyaddr").text(); //slice zip code off caddress = caddress.slice(0, -6); var driverdisplay = $("#orders").find('.driverdisplay'); (i = 0; < driverdisplay.length; i++){ var directionsservice = new google.maps.directionsservice(); var dlats = $(driverdisplay[i]).find('.dlat'); var dlat = $(dlats[0]).text(); var dlngs = $(driverdisplay[i]).find('.dlng'); var dlng = $(dlngs[0]).text(); dlatlng = new google.maps.latlng($('#driverlat').text(), $('#driverlng').text()); var stops = []; var deladdrs = $(driverdisplay[i]).find('.daddr'); (var x = 0; x < deladdrs.length; x++) { var deladdr = $(deladdrs[x]).text(); stops.push({ location: deladdr, stopover: true}); } var request = { origin: dlatlng, destination: caddress, waypoints: stops, travelmode: google.maps.directionstravelmode.driving }; directionsservice.route(request, function (response, status) { if (status == google.maps.directionsstatus.ok) { console.trace(status); var data = response; //$('#eta').text(response.routes[0].legs[0].duration.text); } //else { $('#eta').text("?") } }); } }
you create these variables don't seem use them:
var dlats = $(driverdisplay[i]).find('.dlat'); var dlat = $(dlats[0]).text(); var dlngs = $(driverdisplay[i]).find('.dlng'); var dlng = $(dlngs[0]).text();
i think 1 problem might here:
dlatlng = new google.maps.latlng($('#driverlat').text(), $('#driverlng').text());
jquery's text()
function returns string. google maps' latlng constructor expects floating point numbers. right doing like:
dlatlng = new google.maps.latlng('1.234', '5.678');
you should make sure floats doing:
dlatlng = new google.maps.latlng(parsefloat($('#driverlat').text()), parsefloat($('#driverlng').text()));
Comments
Post a Comment