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
34 lines (24 loc) · 965 Bytes
/
transit.js
File metadata and controls
34 lines (24 loc) · 965 Bytes
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
function getTransitRoute() {
let url = "https://transit.router.hereapi.com/v8/routes" +
"?apiKey=YOUR_API_KEY" +
"&origin=1.40464,103.79009" +
"&destination=1.28675,103.85441" +
"&return=polyline";
fetch(url)
.then(response => response.json())
.then(response => {
let routeGroup = new H.map.Group();
response.routes[0].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();