<uni-forms-item label="所在地区:" name="area" label-align="center" color="#D7D7D7">
<view @click="openPicker()">
<input type="text" v-model="valiFormData.region" placeholder="请选择所在城市" style="border:1px solid #d7d7d7;padding: 5px;border-radius:3px;">
</view>
</uni-forms-item>
<uni-forms-item label="详细地址:" name="address" label-align="center" color="#D7D7D7" style="position: relative;">
<!-- uni-easyinput组件 -->
<uni-easyinput @click="chooseLocation()" v-model="valiFormData.address" placeholder="请输入详细地址" />
<view style="position: absolute;right: 0;top:5px;" @click="chooseLocation()">
<uni-icons type="location " size="25"></uni-icons>
</view>
</uni-forms-item>
<!-- 地区选择组件 -->
<lotus-address v-on:choseVal="choseValue" :lotusAddressData="lotusAddressData"></lotus-address>
import lotusAddress from "@/components/Winglau14-lotusAddress/Winglau14-lotusAddress.vue";
export default {
components: {
lotusAddress,
},
data() {
return {
valiFormData: {
region: '', //所在地区
address: '', //详细地址
},
hasLocation: false,
lotusAddressData: { //省市 区
visible: false,
provinceName: '',
cityName: '',
townName: '',
},
}
},
methods: {
//打开地区选择框
openPicker() {
this.lotusAddressData.visible = true;
},
//选择省市区
choseValue(res) {
this.lotusAddressData.visible = res.visible; //visible为显示与关闭组件标识true显示false隐藏
//res.isChose = 1省市区已选 res.isChose = 0;未选
if (res.isChose) {
this.lotusAddressData.provinceName = res.province; //省
this.lotusAddressData.cityName = res.city; //市
this.lotusAddressData.townName = res.town; //区
this.valiFormData.region = res.province + res.city + res.town;
}
},
//选择具体位置
chooseLocation: function() {
const that = this;
wx.getLocation({
type: 'gcj02', // 'wgs84', // 默认为wgs84的 gps 坐标,如果要返回直接给 openLocation 用的火星坐标,可传入'gcj02'
success: function(res) {
var latitudeer = res.latitude; // 纬度,浮点数,范围为90 ~ -90
var longitudeer = res.longitude; // 经度,浮点数,范围为180 ~ -180。
// var speed = res.speed; // 速度,以米/每秒计
// var accuracy = res.accuracy; // 位置精度
uni.chooseLocation({
latitude: latitudeer, //Number 否 目标地纬度 微信小程序(2.9.0+)、H5-Vue3(3.2.10+)
longitude: longitudeer, //Number 否 目标地经度
success: (res2) => {
that.valiFormData.latitude = res2.latitude;
that.valiFormData.longitude = res2.longitude;
that.hasLocation = true;
that.valiFormData.address = res2.address;
}
})
}
});
},
clear: function() {
this.hasLocation = false
},
}
}
uniapp实现位置功能:
于 2022-07-06 10:36:55 首次发布