-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcrosstimeCalc.js
28 lines (21 loc) · 920 Bytes
/
crosstimeCalc.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
var requester = require("./requester");
function calculateCrosstime(fromGeoloc, toGeoloc, routingManager) {
routingManager = routingManager || "row-RoutingManager";
return requester.get({
host: "www.waze.com",
path: "/" + routingManager + "/routingRequest?from=x%3A" + fromGeoloc.lng + "+y%3A" + fromGeoloc.lat + "&to=x%3A" + toGeoloc.lng + "+y%3A" + toGeoloc.lat + "&at=0&returnJSON=true&returnGeometries=true&returnInstructions=true&timeout=60000&nPaths=1&options=AVOID_TRAILS%3At"
}).then(function (response) {
return calculate(response);
});
}
function calculate(routingDetails) {
var regExp = /"crossTime":(\d+)/g;
var match = regExp.exec(routingDetails);
var sum = 0;
while (match != null) {
sum += parseInt(match[1]);
match = regExp.exec(routingDetails);
}
return sum;
}
exports.calculateCrosstime = calculateCrosstime;