我正在使用 nominatim 进行传单路由。路线完美如我所愿——用户可以在搜索框中输入起点和目的地位置, map 显示两点之间的路线,如下图所示。
但是我想获取目的地位置的坐标。有什么办法可以做到这一点?下面是我如何将 map 添加到我的页面的代码示例。
var map = L.map('map').setView([60.4500, 22.2667], 8);
L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', {
attribution: '© <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
}).addTo(map)
L.Routing.control({
waypoints: [
//L.latLng(60.323935,22.344035)
],
geocoder: L.Control.Geocoder.nominatim()
}).addTo(map);
最佳答案
查看RoutingResultEvent .每次成功计算路线时都会调用它。处理程序将收到的事件包含用于路线的路标。
基本上是这样
var x = L.Routing.control({
// YOUR STUFF
geocoder: L.Control.Geocoder.nominatim()
}).addTo(map);
x.on("routesfound", function(e) {
var waypoints = e.waypoints || [];
var destination = waypoints[waypoints.length - 1]; // there you have the destination point between your hands
});
关于javascript - 传单路由中的目的地坐标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34045265/