uni-app地图拖动如何使用getCenterLocation获取地图中心点

地图在打车及服务网站或小程序等中极为常见,使用地图可以极为便捷的帮助用户进行相关操作。

那么在uni-app多端框架中,可以如何获取地图的中心点经纬度呢?

接下来就来介绍如何使用getCenterLocation来获取地图中心点的经纬度信息。

<map id="map" class="six_map" :latitude="latitude" :longitude="longitude" @regionchange="changeEvent"></map>
<script>
export default {
data() {
return {
longitude: '103.375903',
latitude: '33.825686',
mapContext: null
}
},
onLoad() {
this.mapContext = uni.createMapContext('map')
},
methods: {
changeEvent(e) {
let _this = this
if (e.type === 'end' && e.causedBy === 'drag') {
_this.mapContext.getCenterLocation({
success: res => {
console.log("res", res)
},
fail: (err) => {
console.log('err', err)
}
})
}
}
}
}
</script>

getCenterLocation功能描述:

    获取当前地图中心的经纬度。返回的是 gcj02 坐标系,可以用于 wx.openLocation()

六月初字帖坊小程序 你想要的字帖模板及工具,这里都有!