-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcrosstimeFetcher.js
35 lines (31 loc) · 1.16 KB
/
crosstimeFetcher.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
29
30
31
32
33
34
35
var Q = require("q");
var autocomplete = require("./autocomplete.js");
var geolocation = require('./geolocation.js');
var crosstimeCalc = require('./crosstimeCalc.js');
function getCrossTime(from, to) {
return Q
.all([autocomplete.getAutoCompleteOptions(from),
autocomplete.getAutoCompleteOptions(to)])
.then(function (predictions) {
return [geolocation.getGeoLocation(predictions[0][0].reference),
geolocation.getGeoLocation(predictions[1][0].reference)];
})
.spread(function (fromGeoloc, toGeoloc) {
var fromLoc = fromGeoloc.result.geometry.location;
var toLoc = toGeoloc.result.geometry.location;
var routingManager = getRoutingManagerName(fromGeoloc);
return crosstimeCalc.calculateCrosstime(fromLoc, toLoc, routingManager);
});
}
function getRoutingManagerName(geoloc) {
var country = geoloc.result["address_components"][1]["short_name"];
switch (country) {
case "IL":
return "il-RoutingManager";
case "US":
return "RoutingManager";
default:
return "row-RoutingManager";
}
}
exports.getCrossTime = getCrossTime;