-
Notifications
You must be signed in to change notification settings - Fork 3
Open
Description
I'm stuck for hours trying to get the total distance driving
here is my code :
function getDistanceBetweenPoints(userLat, userLng, resLat, resLng) {
var params = {
origin: { userLat, userLng },
destination: { resLat, resLng },
key: "AIzaSyDeKxeg2T-aM2oHSdwk-iIffE_YFLDYX6k",
units: 'metric'
};
return new Promise((resolve, reject) => {
map.getDistance(params, (err, data) => {
if (err) {
reject(err);
}
resolve(data);
});
});
}
getDistance: function(params, cb) {
// validate inputs to npm module
var validateErr = validateInput(params, cb);
if (validateErr) {
return cb(validateErr);
}
// build query URL
var url = "https://maps.googleapis.com/maps/api/directions/json?" + qs.stringify(params);
// make request to google server
request(url, function(err, res, body) {
var jsonRes = JSON.parse(body)
for(i = 0; i < jsonRes.routes[0].legs.length; i++){
distance += parseFloat(jsonRes.routes[0].legs[i].distance.value);
}
return cb(err, distance);
});
},
what's wrong ?
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels