4

Asking to OSRM for a route, OSRM is returning the geometry:

"route_geometry":"ity_rArqlxIvTv|AoCrY"

After decode them, I'm getting 3 GPS coordinates:

43.529557,          -5.659434
43.529208999999994, -5.660934
43.529281,          -5.66136

But with just 3 points, I'm getting this route :(

enter image description here

How can I draw a right route on the road with openlayers? Like this:

enter image description here

3 Answers 3

3

The route geometry you get is a encoded polyline. You can create a route from it as follows:

// route is ol.geom.LineString
var route = new ol.format.Polyline({
    factor: 1e6
}).readGeometry(polyline, {
    dataProjection: 'EPSG:4326',
    featureProjection: 'EPSG:3857'
});
var feature = new ol.Feature(route);
feature.setStyle(styles.route);
vectorSource.addFeature(feature);

Source : http://jsfiddle.net/jonataswalker/079xha47/

3

With Latest API use

overview simplified (default), full, false Add overview geometry either full, simplified according to highest zoom level it could be display on, or not at all.

curl 'http://router.project-osrm.org/route/v1/driving/-1.8744130630953275,52.45318441573963;-1.879401971863028,52.451059431849615;-1.8783612747652496,52.44962092302177;-1.882395317123648,52.44969938835112;-1.8824275036318268,52.452046744809195;-1.8794663448793851,52.45332825709778;-1.8898840446932288,52.454230523991356?overview=full'

1

The solution is to add this parameter: https://router.project-osrm.org/viaroute?z=18& Then, it will return so many points as the zoom (18 in this example) :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.