1.引入腾讯地图插件
mp.weixin.qq.com/wxopen/plug…
2. 页面使用
<button bindtap="getAddress">获取位置信息</button>
<input type="text" value='{{location||""}}' />
<map markers="{{marks}}" style="width:100%;" latitude="{{latitude}}" longitude='{{longitude}}'></map>
const chooseLocation = requirePlugin('chooseLocation');
location: '',
marks: [],
latitude: '',
longitude: '',
onShow() {
if (chooseLocation.getLocation()) {
const {
address,
latitude,
longitude,
} = chooseLocation.getLocation();
let marks = [{
latitude,
longitude,
}]
this.setData({
location: address,
marks,
latitude: parseFloat(latitude),
longitude: parseFloat(longitude),
})
console.log(this.data.marks)
} else {
let that = this
wx.getLocation({
type: 'gcj02',
altitude: true,
success(res) {
let {
latitude,
longitude,
} = res
let marks = [{
latitude,
longitude,
}]
that.setData({
marks,
latitude,
longitude,
})
}
})
}
},
getAddress() {
const key = '';
const referer = '';
const location = JSON.stringify({
latitude:this.data.latitude,
longitude:this.data.longitude
});
wx.navigateTo({
url: `plugin://chooseLocation/index?key=${key}&referer=${referer}&location=${location}`
});
},