.wxml
<view class="input-info">
<label>地方</label>
<picker mode="region" name="regionName" bindtap="changeRegion" bindchange="bindRegionChange" value="{{region}}" custom-item="{{customItem}}" class="choose-region" style="border-bottom:1px solid #ddd">
<view class="picker">
{{region[0] }} {{region[1] }} {{region[2]}}
</view>
</picker>
</view>
.js
var QQMap = require('../../qqmap-wx-jssdk1.2/qqmap-wx-jssdk');
var qqmapsdk = new QQMap({
key: key // 必填
});
Page({
data:{
region:[]
}
onLoad: function () {
// 查看是否授权,获取位置信息
var that = this
var wei = this.lc(function (wei) {
qqmapsdk.reverseGeocoder({
location:{
//纬度
latitude: wei.latitude,
//经度
longitude: wei.longitude
},
success: function (res) {
console.log(res.result.address)
var location = [];
location.push(res.result.address_component.province,res.result.address_component.city,res.result.address_component.district);
that.setData({
region: location
})
},
fail: function (res) {
console.log(res);
}
})
});
},
lc: function (wei) {
var self = this
wx.getLocation({
type: 'wgs84',
success: function (res) {
wei(res);
return wei;
}
})
},
// 改变县区选择
bindRegionChange: function (e) {
this.setData({
region: e.detail.value
})
},
})