[英]Mapbox autocomplete get Long and Lat
I'm using Mapbox with autocomplete in a vue component: 我在vue组件中使用具有自动完成功能的Mapbox:
<template>
<div>
<div id='geocoder'></div>
</div>
</template>
<script>
import mapboxgl from 'mapbox-gl';
export default {
data() {
return {
map: null
}
},
created() {
Event.$on('map-created', (map) => {
this.map = map;
let geocoder = new MapboxGeocoder({
accessToken: mapboxgl.accessToken,
});
document.getElementById('geocoder').appendChild(geocoder.onAdd(this.map));
});
}
}
</script>
It's working but how do I get the long and lat when a user clicks on a result? 它正在工作,但是当用户单击结果时如何获得经度和纬度?
Is there some kind of event? 有什么活动吗? Couldn't find anything in the docs.
在文档中找不到任何内容。
Thanks! 谢谢!
Try this: 尝试这个:
this.map.on('click', '[YOUR LAYER ID]', (event) => {
console.log(event.features[0].geometry.coordinates);
});
It helps me when I add my own layers. 当我添加自己的图层时,它对我有帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.