<template>
<view>
<view class="" style="height: 500rpx;"></view>
<button @click="chooseLocation">打开地图选择位置</button>
</view>
</template>
<script>
export default {
data() {
return {
address: ''
};
},
methods: {
// 打开地图选择位置
chooseLocation() {
// 此处拿到的this才是指向vc
const that = this;
// 发起授权请求
// 打开地图选择位置
uni.chooseLocation({
success(res) {
console.log('位置名称:' + res.name);
console.log('详细地址:' + res.address);
console.log('纬度:' + res.latitude);
console.log('经度:' + res.longitude);
that.address = res.address;
// 此处如果直接使用this, 是无法获取到data里面的数据的,因为此处this指向不是vc
}
});
},
}
}
</script>
uniapp地图选点功能
最新推荐文章于 2024-06-11 15:49:11 发布