【问题标题】:Get adress origin and destination in mapbox gl directions在 mapbox gl 方向中获取地址起点和终点
【发布时间】:2020-05-14 20:13:37
【问题描述】:

我正在使用来自 mapboxmapbox gl 方向,它在 mapbox 文档的示例中使用。

但是,我无法获取用户输入的地址值。

我需要用户选择的地址。谢谢!

这是我的代码:

<script>

    mapboxgl.accessToken = 'MY TOKEN ACCESS';

    var map = new mapboxgl.Map({
        container: 'map',
        style: 'mapbox://styles/mapbox/streets-v11',
        center: [-79.4512, 43.6568],
        zoom: 13
    });

    map.addControl(
        new MapboxDirections({
            accessToken: mapboxgl.accessToken
        }),
        'top-left'
    );
</script>

【问题讨论】:

    标签: javascript laravel mapbox mapbox-gl-js mapbox-gl


    【解决方案1】:
    // Docs for route event is here:
    // https://github.com/mapbox/mapbox-gl-directions/blob/master/API.md#on`enter code here`
        directions.on('route', e => {
    // routes is an array of route objects as documented here:
    // https://docs.mapbox.com/api/navigation/#route-object:
          let routes = e.route
            routes.map(r => r.legs[0].steps[0].name)//get the origin
            tail=routes.map(r => r.legs[0].steps.length)//get length of instructions
            routes.map(r => r.legs[0].steps[tail-1].name)//get destination
          });
    

    【讨论】:

      【解决方案2】:

      mapbox-gl-directions plugin 提供了getOrigingetDestination 方法,分别用于检索当前路由的起点和终点。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2019-01-02
        • 2020-09-30
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多