forked from alletsz/devrel-workshops
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtransit.js
More file actions
38 lines (28 loc) · 1.08 KB
/
transit.js
File metadata and controls
38 lines (28 loc) · 1.08 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
function getTransitRoute() {
let url = "https://transit.router.hereapi.com/v8/routes" +
"?apiKey=YOUR_API_KEY" +
"&origin=52.5214,13.41555" +
"&destination=52.50715,13.39061" +
"&return=polyline" +
"&arrivalTime=2020-07-03T09:00:00" +
"&alternatives=1";
fetch(url)
.then(response => response.json())
.then(response => {
let routeGroup = new H.map.Group();
response.routes.forEach(route => {
route.sections.forEach(section => {
let lineString = H.geo.LineString.fromFlexiblePolyline(section.polyline);
var polyline = new H.map.Polyline(lineString, { style: { lineWidth: 10 } });
routeGroup.addObject(polyline);
});
});
map.addObject(routeGroup);
map.getViewModel().setLookAtData({
bounds: routeGroup.getBoundingBox()
});
}, error => {
console.log.error(error);
});
}
getTransitRoute();