Reputation: 266
I am getting back a ZERO RESULTS status when I make a call using the google directions service when I shouldn't, as far as I can see. I have walked through the debugger and it looks like my values are correct. I am using the directions service route method with waypoints. For origin, I need to use lat, lng vals because that is constantly changing, but for waypoints and destination, I use a full address. Waypoint addresses don't have country at end and stops at US state, but destination does have country value in the address. I wouldn't think that's a problem. All addresses are in the US, even in the same state.
Anybody see something wrong with my code and how it could be causing this, assuming the values being filled in are correct?
function setRoute() {
var wayPts = "";
var cAddress = $("#companyAddr").text();
//slice the zip code off
cAddress = cAddress.slice(0, -6);
var driverDisplay = $("#orders").find('.driverDisplay');
for (i = 0; i < 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');
for (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("?") }
});
}
}
Upvotes: 0
Views: 1868
Reputation: 31912
You create these variables but then don't seem to 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 one problem might be here:
dLatLng = new google.maps.LatLng($('#driverLat').text(), $('#driverLng').text());
jQuery's text()
function returns a string. Google Maps' LatLng constructor expects floating point numbers. Right now this is probably doing something like:
dLatLng = new google.maps.LatLng('1.234', '5.678');
You should make sure those are floats by doing:
dLatLng = new google.maps.LatLng(parseFloat($('#driverLat').text()), parseFloat($('#driverLng').text()));
Upvotes: 2