<template>
<view class="box">
<view class="map">
<u-input v-model="value" :type="type" :border="border" @click="inputHandle" />
<map @tap="clickHandle" id="map" :latitude="latitude" :longitude="longitude" :markers="markers></map>
</view>
</view>
</template>
<script>
export default {
data() {
return {
value: uni.getStorageSync('address') ? uni.getStorageSync('address') : '',
type: 'text',
border: true,
latitude: '',
longitude: '',
markers:[
{
latitude: '',
longitude: '',
iconPath:'../../static/imgs/bg.png'
}
],
}
},
methods: {
frame() {
uni.chooseLocation({
success: res => {
this.latitude = res.latitude;
this.longitude = res.longitude;
this.value = res.address;
this.markers[0].latitude = res.latitude;
this.markers[0].longitude = res.longitude;
this.markers[0].iconPath = '../../static/imgs/map.png';
}
});
},
onLoadHadnle() {
uni.getLocation({
type: 'wgs84',
success: res => {
this.longitude = res.longitude;
this.latitude = res.latitude;
this.markers[0].latitude = res.latitude;
this.markers[0].longitude = res.longitude;
this.markers[0].iconPath = '../../static/imgs/map.png';
}
});
},
inputHandle(e) {
this.frame();
},
clickHandle(e) {
this.frame();
}
},
created() {
this.onLoadHadnle();
}
}
</script>
<style lang="scss" scoped>
.box {
height: 100vh;
.map {
width: 100%;
height: 100%;
map {
width: 100%;
height: 100%;
}
}
}
</style>
uni-app实现地图输入选择地址
最新推荐文章于 2025-03-18 23:16:39 发布