3

我正在使用 nominatim 进行传单路由。路由完美地按照我的意愿工作 - 用户可以在搜索框中输入目的地位置,地图显示两点之间的路线,如下图所示。 在此处输入图像描述

但我想获取目的地位置的坐标。我有什么办法可以做到这一点?下面是我如何将地图添加到我的页面的代码示例。

var map = L.map('map').setView([60.4500, 22.2667], 8);


    L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', {
        attribution: '&copy; <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);
4

2 回答 2

2

查看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

});
于 2015-12-03T16:13:18.223 回答
0

您可以使用:

routeControl.on("routesfound", function(e) {
    coordinates=e.routes[0].coordinates;
    destination=coordinates[coordinates.length-1];
});

那里有坐标,航点与坐标不一样,您要查找的是找到的路线的坐标,而不是您要求的航点,然后您可以取坐标。长度- 1 你会得到你想要的

于 2016-12-22T08:18:06.380 回答