fou*_*rix 5 mapbox mapbox-gl-js
我只需要没有地图的 mapbox 地理编码自动完成(将带有 lat/lng 的结果放在另一个请求中)
我设法在没有地图的情况下完全单独使用它:
<template>
<div id='geocoder' class='geocoder'></div>
</template>
<script>
import MapboxGeocoder from '@mapbox/mapbox-gl-geocoder'
require('../../node_modules/@mapbox/mapbox-gl-geocoder/dist/mapbox-gl-geocoder.css')
mapboxgl.accessToken = '<your access token here>';
var geocoder = new MapboxGeocoder({
accessToken: mapboxgl.accessToken
placeholder: 'Rechercher'
});
document.getElementById('geocoder').appendChild(geocoder.onAdd());
</script>
Run Code Online (Sandbox Code Playgroud)
但是现在我想检索数据(特别是 lat/lng 属性,以便将其保存在我的组件中并使用它)
我怎样才能做到这一点 ?我已经搜索了 mapbox 文档,但没有找到任何相关信息:/
提前感谢社区
And*_*vey 11
从 API 文档https://github.com/mapbox/mapbox-gl-geocoder/blob/master/API.md#on你可以使用
geocoder.on('results', function(results) {
console.log(results);
})
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4204 次 |
| 最近记录: |