-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcreateDistanceMatrix.js
More file actions
65 lines (58 loc) · 1.27 KB
/
createDistanceMatrix.js
File metadata and controls
65 lines (58 loc) · 1.27 KB
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// https://github.com/radarlabs/radar-sdk-js
// https://radar.com/documentation/sdk/web
function createDistanceMatrix (originsArr, destinationsArr) {
API_KEY = "prj_test_pk_782c752373db12dbd94e9a8de91a108f249a6ab6"
var matrix = [];
Radar.initialize(API_KEY);
Radar.getMatrix({
origins: originsArr,
destinations: destinationsArr,
modes: 'car',
units: 'imperial'
}, function(err, result) {
if (!err) {
// do something with result.matrix
radarMatrix = result.matrix;
for (let i=0; i < radarMatrix.length; i++) {
matrix.push([]);
for (let j=0; j < radarMatrix[i].length; j++) {
matrix[matrix.length - 1].push(radarMatrix[i][j].duration.value);
}
}
}
});
return matrix;
}
originsArr = [{
latitude: 39.0185856,
longitude: -77.0120635
},
{
latitude: 39.064102,
longitude:-76.9455316
},
{
latitude: 39.0804086,
longitude:-76.942484
},
{
latitude:39.1112467,
longitude:-76.9364229
}];
destinationsArr = [{
latitude: 39.0185856,
longitude: -77.0120635
},
{
latitude: 39.064102,
longitude:-76.9455316
},
{
latitude: 39.0804086,
longitude:-76.942484
},
{
latitude:39.1112467,
longitude:-76.9364229
}];
console.log(createDistanceMatrix(originsArr, destinationsArr));