I'm having trouble displaying the line between two points, when I use any Lat / Long without the "-", it works, but when I get a (-23.563210, -46.654250) that has "-", it does not work anymore.
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));
let routingParameters = {
mode: 'fastest;car',
waypoint0: "-23.56277,-46.65459",
waypoint1: '52.5206,13.3862',
representation: 'display',
routeattributes: 'waypoints,summary,shape,legs',
maneuverattributes: 'direction,action'
};
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: 'blue', lineWidth: 10 }
})
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, startMarker, endMarker]);
map.setViewBounds(routeLine.getBounds());
}
}
let router = platform.getRoutingService();
router.calculateRoute(routingParameters, onResult,
(error) => {
alert(error.message);
})