Como colocar a latitude e a longitude da marca mais proxima na rota(routing) com HERE maps api.

25/10/2019

5

Bom dia pessoa, preciso que me ajudem a colocar a latitude e a longitude da marca mais proxima na routa(routing) do here maps api. para criar um caminho que sai da marca mais proxima e vai ate a localização pretendida. Ajudem me por favor é urgente.

quando uso o codigo abaixo, não acontece nada:

function findNearestMarker(coords) {
var minDist = 90000,
nearest_text = ''*None*'',
markerDist,
latit = 0,
longit = 0,
// get all objects added to the map
objects = map.getObjects(),
len = map.getObjects().length,
i;

// iterate over objects and calculate distance between them
for (i = 0; i < len; i += 1) {
markerDist = objects[i].getGeometry().distance(coords);
if (markerDist < minDist) {
minDist = markerDist;
nearest_text = objects[i].getData();
latit = objects[i].getGeometry().lat;
longit = objects[i].getGeometry().lng;
}
}

logEvent(''The nearest marker is: '' + nearest_text + '' lat:'' + latit + '' long:'' + longit);
alert(`$`);
}

function proximidade(){

// Create the parameters for the routing request:
var routingParameters = {
// The routing mode:
''mode'': ''fastest;car'',
// The start point of the route:
''waypoint0'': `$,$`,
// The end point of the route:
''waypoint1'': ''geo!52.5309916298853,13.3846220493377'',
// To retrieve the shape of the route we choose the route
// representation mode ''display''
''representation'': ''display''
};

// Define a callback function to process the routing response:
var onResult = function(result) {
var route,
routeShape,
startPoint,
endPoint,
linestring;
if(result.response.route) {
// Pick the first route from the response:
route = result.response.route[0];
// Pick the route''s shape:
routeShape = route.shape;

// Create a linestring to use as a point source for the route line
linestring = new H.geo.LineString();

// Push all the points in the shape into the linestring:
routeShape.forEach(function(point) {
var parts = point.split('','');
linestring.pushLatLngAlt(parts[0], parts[1]);
});

// Retrieve the mapped positions of the requested waypoints:
startPoint = route.waypoint[0].mappedPosition;
endPoint = route.waypoint[1].mappedPosition;

// Create a polyline to display the route:
var routeLine = new H.map.Polyline(linestring, {
style: { strokeColor: ''blue'', lineWidth: 3 }
});

// Create a marker for the start point:
var startMarker = new H.map.Marker({
lat: startPoint.latitude,
lng: startPoint.longitude
});

// Create a marker for the end point:
var endMarker = new H.map.Marker({
lat: endPoint.latitude,
lng: endPoint.longitude
});

// Add the route polyline and the two markers to the map:
map.addObjects([routeLine, startMarker, endMarker]);

// Set the map''s viewport to make the whole route visible:
map.getViewModel().setLookAtData({bounds: routeLine.getBoundingBox()});
}
};

// Get an instance of the routing service:
var router = platform.getRoutingService();

// Call calculateRoute() with the routing parameters,
// the callback and an error callback function (called if a
// communication error occurs):
router.calculateRoute(routingParameters, onResult,
function(error) {
alert(error.message);
});
Responder

Utilizamos cookies para fornecer uma melhor experiência para nossos usuários. Para saber mais sobre o uso de cookies,
consulte nossa política de privacidade. Ao continuar navegando em nosso site, você concorda com a nossa política.

Aceitar