核心:
- 使用
baidu-map的click方法 BMap.Geocoder()下的getLocation({lng, lat}, function(result) {})
<baidu-map
:zoom="10"
@ready="handleReady"
@click="clickInfo"
:scroll-wheel-zoom="true"
:center="center"
:mapClick="false">
</baidu-map>
methods: {
handleReady({ BMap, map }) {
this.BMap = BMap
this.map = map
},
clickInfo(e) {
if (e.type == 'click') {
new this.BMap.Geocoder().getLocation(e.point, res => {
console.log(res, 'result.addressComponents')
let result = res.addressComponents
})
}
}
}
打印结果
这篇博客介绍了如何在Vue应用中结合Baidu地图API,利用`BMap.Geocoder()`服务监听地图点击事件,获取点击位置的详细地址。通过`@click`事件和`getLocation`方法,实现了地图交互功能,从而能够从用户点击的地图坐标中获取地址信息。
3559

被折叠的 条评论
为什么被折叠?



