admin管理员组文章数量:1332353
I have some gps generated data during a drive.
var routeArr = [{lng1, lat1}, {lng2,lat2}, {lng3, lat3}.....];
I want to show this generated data as actual route traveled on a Leaflet powered Openstreet map. My naive approach is to show a polyline connecting all points. But I want to show actual route which was followed while driving. Can I use OSRM-Backend API with leaflet-routing-machine plugin for this? Any help will be much appreciated.
I have some gps generated data during a drive.
var routeArr = [{lng1, lat1}, {lng2,lat2}, {lng3, lat3}.....];
I want to show this generated data as actual route traveled on a Leaflet powered Openstreet map. My naive approach is to show a polyline connecting all points. But I want to show actual route which was followed while driving. Can I use OSRM-Backend API with leaflet-routing-machine plugin for this? Any help will be much appreciated.
Share Improve this question edited May 20, 2016 at 11:31 Anant asked May 20, 2016 at 11:22 AnantAnant 3,0773 gold badges28 silver badges33 bronze badges1 Answer
Reset to default 6Sadly there is not drop-in way to use this with LRM since the APIs work slightly differently.
- The response contains
tracepoints
andmatchings
instead ofwaypoints
androutes
- An object in the
matchings
array is similar to aRoute
object but it represent sections of the gps trace that could be matched, not alternative routes like in the route plugin.
Easiest way to just deploy this on a map would be to run a query against:
http://router.project-osrm/match/v1/driving/{lon,lat};{lon,lat};...?overview=full
And then use https://github./mapbox/polyline and the following snippet to add the geometry on a map:
var polyline = require('polyline');
/* fetch the URL and save JSON in response */
response.matchings.map((m) => L.polyline(polyline.decode(m.geometry)).addTo(map));
本文标签: javascriptHow to use OSRM match api in leaflet to draw a routeStack Overflow
版权声明:本文标题:javascript - How to use OSRM match api in leaflet to draw a route? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742321865a2452949.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论