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
39 lines (29 loc) · 1.11 KB
/
transit.js
File metadata and controls
39 lines (29 loc) · 1.11 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
function getTransitRoute() {
let url = "https://transit.router.hereapi.com/v8/routes" +
"?apiKey=YOUR_API_KEY" +
"&origin=40.74843,-73.98567" +
"&destination=40.78193,-73.97239" +
"&return=polyline,fares" +
"&modes=-subway" +
"&changes=2";
fetch(url)
.then(response => response.json())
.then(response => {
let routeGroup = new H.map.Group();
response.routes.forEach(route => {
console.log(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();