代码语言:javascript复制
<map id="maps" style="width: 100%" class="myMap position-absolute top-0 left-0 right-0 bottom-0"
:style="{height: `${mapHeight}rpx`}" :latitude="latitude" :longitude="longitude" :polygons="pol"
@regionchange="regionChange">
</map>
代码语言:javascript复制regionChange(e) {
// 地图中心点坐标
this.getCenterLanLat()
}
代码语言:javascript复制 // 获取当前地图中心的经纬度
getCenterLanLat() {
this.mapContext = uni.createMapContext("maps", this);
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;
console.log("地址")
console.log(address)
this.$emit('longLatDetail', address)
},
fail: (err) => {
console.log(this.latitude)
console.log('获取当前地图中心的经纬度2', err);
}
})
},