@regiοnchange="regionchange" : 地图滑动调用的方法
<map id="maps" class="map" :longitude="longitude" :latitude="latitude" :markers="markers" :polyline="polyline" :include-points="points"
@tap="mapTap" @regionchange="regionchange"></map>
regionchange(event) {
console.log('regionchange', event)
if(event.type =='end'){
this.getCenterLanLat()
}
},
// 获取当前地图中心的经纬度
getCenterLanLat() {
this.mapContext = uni.createMapContext("maps", this);
console.log('获取中心点', this.mapContext)
this.mapContext.getCenterLocation({
type: 'gcj02',
success: (res) => {
let address = {
latitude: res.latitude,
longitude: res.longitude
}
this.markers[0].longitude = address.longitude;
this.markers[0].latitude = address.latitude;
this.$emit('longLatDetail', address)
},
fail:(err)=>{
console.log(this.latitude)
console.log('获取当前地图中心的经纬度2', err);
}
})
},
注意:这个地图组件是我自定义的组件,所以获取this.mapContext = uni.createMapContext("maps", this);必须传入this,否则获取不到地图中心的经纬度
this.mapContext = uni.createMapContext("maps", this);