<view class="ditu" v-if="markersLoaded">
<map style="width:100%;height:100%;" :latitude="latitude" :longitude="longitude"
:scale="scale" :markers="covers" @tap="shareLocation">
</map>
</view>
<script>
export default {
data() {
return {
latitude: 34.35073, //纬度
longitude: 107.368993, //经度
scale: 16, //地图缩放程度
covers: [],
markersLoaded: false // 标记是否加载完毕
};
},
onLoad(options) {
this.getaddress()
},
methods: {
getaddress() {
addressexport(this.form.interviewAddressId).then(res => {
console.log(res.data);
if (res.data.lat != null) {
let addressdate = [res.data]
addressdate.map((item) => {
this.covers.push({
id: 1,
latitude: item.lat,
longitude: item.lon,
detailText: item.detailText,
iconPath: "https://hellouniapp.dcloud.net.cn/static/location.png",
width: 50,
height: 50
})
this.latitude = item.lat
this.longitude = item.lon
})
this.markersLoaded = true
} else {//如果没有设置默认地址
this.covers = [{
id: 1,
latitude: 34.35073,
longitude: 107.368993,
detailText: "detailText",
iconPath: "https://hellouniapp.dcloud.net.cn/static/location.png",
width: 50,
height: 50
}]
this.markersLoaded = false
}
})
},
shareLocation() {
wx.openLocation({
longitude: Number(this.longitude),
latitude: Number(this.latitude),
name: this.covers[0].detailText,
scale: 16,
success: res => {
console.log('打开地图成功:', res)
},
fail: res => {
console.log('打开地图失败:', res)
},
});
},
},
};
</script>
uniapp使用腾讯地图展示地址
于 2024-08-17 09:46:03 首次发布