wxml代码 点击获取地址:
<l-input label="位置" bindtap="map" required="{{true}}" value="{{onenumber}}" placeholder="小区名称或地址" />
js代码
//地图获取位置
map:function(res){
var _this = this;
//先查清楚经纬度
wx.getLocation({
type: 'wgs84',
success (res) {
const latitude = res.latitude
const longitude = res.longitude
_this.setData({
latitude,
longitude
})
}
})
//再通过经纬度查询详细地址
wx.chooseLocation({
latitude: _this.data.latitude,
longitude: _this.data.longitude,
success: function(daname){
console.log(daname)
_this.setData({
onenumber:daname.name
})
}
})
},
app.json
"permission": {
"scope.userLocation": {
"desc": "你的位置信息将用于小程序位置接口的效果展示"
}
},