在页面上放置一个map组件
<map id="mapId" ref="mapId" style="width: 750rpx; height:calc(100vh - 120rpx);"
:latitude="latitude" :longitude="longitude" :markers="markers" @regionchange="onRegionChange">
函数编写
//获取中心点位置
getCenterLatLong(){
let mapObjs = uni.createMapContext('mapId', this) // 得到map实例对象
mapObjs.getCenterLocation({
success: res=>{
console.log('p000:',res)
},
fail: res=>{
console.log('p1111:',res)
},
complete: res=>{
console.log('p222:',res)
}
})
},
函数调用
// 地图移动时触发
onRegionChange(e){
if (e.type === 'end') { //在安卓中是 end 事件
this.getCenterLatLong() // 地图移动时获取中心点的经纬度
}else if(e.type ==='regionchange'){ // 在ios中是 regionchange
this.getCenterLatLong()
}
},