0
I’m trying to make a route between two points using HereMaps
, until then all right, I got it, however, it does not go through the street, but through the whole map.
How I would make him go down the street HereMaps
, the example works perfectly.
My code
let platform = new H.service.Platform({
'app_id': '',
'app_code': ''
})
let defaultLayers = platform.createDefaultLayers()
let map = new H.Map(
document.getElementById('map'),
defaultLayers.normal.map,
{
zoom: 15,
center: {lat: -23.5627, lng: -46.6546}
}
)
let behavior = new H.mapevents.Behavior(new H.mapevents.MapEvents(map));
if (this.habCaminho) {
let routingParameters = {
mode: 'fastest;truck',
representation: 'display',
waypoint0: "geo!23.56277,46.65459",
waypoint1: "geo!" + marc1
};
let onResult = function (result) {
let route,
routeShape,
startPoint,
endPoint,
linestring
if (result.response.route) {
route = result.response.route[0]
routeShape = route.shape
linestring = new H.geo.LineString()
routeShape.forEach(function (point) {
let parts = point.split(',')
linestring.pushLatLngAlt(-parts[0], -parts[1])
});
startPoint = route.waypoint[0].mappedPosition
endPoint = route.waypoint[1].mappedPosition
let routeLine = new H.map.Polyline(linestring, {
style: {strokeColor: '#045993', lineWidth: 5},
arrows: {fillColor: 'white', frequency: 2, width: 0.8, length: 0.7}
})
let startMarker = new H.map.Marker({
lat: -startPoint.latitude,
lng: -startPoint.longitude
})
let endMarker = new H.map.Marker({
lat: -endPoint.latitude,
lng: -endPoint.longitude
})
map.addObjects([routeLine]);
map.setViewBounds(routeLine.getBounds(), true);
}
}
let router = platform.getRoutingService();
router.calculateRoute(routingParameters, onResult,
(error) => {
alert(error.message);
})
}