Closed AlessandroMFerreira closed 4 years ago
Hello,
I started using the Leaflet routing machine a short time ago and I came across the following problem:
I need to plot a route on the map with latitude and longitude data stored in a database that in turn come from a location device that is installed on some cars. My problem here is that when using leaflet polylines the lines that are drawn on the map do not follow the route of the highway, and often when there are curves the lines end up leaving the highway.
When using the Leaflet Routing machine most of the route is perfectly designed, however in some cases where there are curves or intersections in the route it seems to calculate the best route between the two closest points and ends up generating meaningless routes.
I just want to show on the map the route taken by the car and not calculate the best route. I don't know if it's my lack of experience or if I don't know what to look for to solve this problem but any help would be welcome.
The image below using the Leaflet routing machine. The red arrow should be the path that should be drawn on the map, but it makes this outline marked in black
Note: I created my own OSRM server, the latitude and longitude points easily pass the 1700 points.
Here is the code I used
` function(){ jsonRota = self.montaJsonRota(); $.ajax({ type: "POST", url: location.origin + '/sis/' + jsGet('sis') + "/framework/Localizacao.php", dataType: 'JSON', cache: false, data: {jsonRota: jsonRota, "sis": jsGet("sis")}, success: function(response){ var arrayLngLat = [];
for(var i = 0; i < response.rota.length -1; i++){
arrayLngLat.push(L.latLng(response.rota[i].lat.replace(",","."), response.rota[i].lng.replace(",",".")));
}
var route = new L.Routing.OSRMv1({
serviceUrl: 'http://localhost:5000/route/v1',
useHints: false,
timeout: 60000
});
//var polyline = L.polyline(arrayLngLat).addTo(self.mapa);
var control = L.Routing.control({
router: route,
lineOptions: {
styles: [{color: '#0066ff', opacity: 0.7, weight: 5}]
},
waypoints: arrayLngLat,
routeWhileDragging: false,
show: false,
waypointMode: 'snap',
autoRoute: true,
showAlternatives: false
});
control.addTo(self.mapa);
control.hide();
}
});
}`
If you are trying to match up an existing GPS route against the road network, you are better off using OSRM's match service, which is specifically designed for with this use case in mind. I believe it is less likely to return routes like the one in your example.
Having said that, this is outside the scope of Leaflet Routing Machine, so closing.
Ok,
Thankyou very much!!
Hi there, before submitting a new issue, please consider the following: