获取2个标记之间的距离 [英] Getting distance between 2 markers

查看:82
本文介绍了获取2个标记之间的距离的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想获取2个标记之间的距离,而不是直线,更像是此插件中的真实路径-

https://github.com/perliedman/leaflet-routing-machine

我在指令中找不到有关使用此插件的任何信息:angular-leaflet-directive, 如果有人可以指导如何做到这一点,将不胜感激.

谢谢!

解决方案

我不确定您是否特别想使用传单路由机来获取距离...但是,如果这样做,也许此信息可以帮助您入门: /p>

由小叶路由机器作者根据此示例在您的地图上设置路线:

https://www.liedman.net/leaflet-routing-机器/教程/互动/

如果查看该示例,则有一个名为routes的数组.每个路由都有一些由OSRM生成的与之相关的基本统计信息.您可以通过调用以下命令来拉动它们:

routes[0].summary.totalDistance

routes[0].summary.totalTime

然后,您可以对他们进行任何您想做的事情.如果您在GitHub上浏览代码,则可以了解有关如何在插件内移动数据以及数组排列方式的更多信息:

https://unpkg.com /leaflet-routing-machine@3.2.12/dist/leaflet-routing-machine.js

I would like to get the distance between 2 markers but not as a direct line, more as a real path like it goes in this plugin -

https://github.com/perliedman/leaflet-routing-machine

I didn't find anything about using this plugin in the directive: angular-leaflet-directive, if someone can guide how to make it done, it would be very appreciated.

thanks!

解决方案

I am not sure if you specifically want to use leaflet routing machine to get distances... but if you do, maybe this info can get you started:

Set up a route on your map based on this example by the leaflet routing machine author:

https://www.liedman.net/leaflet-routing-machine/tutorials/interaction/

If you look at that example, there is an array called routes. Each route has some basic statistics associated with it, generated by OSRM. You can pull them by calling for example:

routes[0].summary.totalDistance

or

routes[0].summary.totalTime

Then you can do whatever you want with them. If you dig through the code on GitHub you can see more about how the data are moved around within the plugin and why the array is arranged that way:

https://unpkg.com/leaflet-routing-machine@3.2.12/dist/leaflet-routing-machine.js

这篇关于获取2个标记之间的距离的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆