微信小程序自带的地图,首先wxml
<view style="flex: 1;text-align: left;" bindtap="getLocation">
<image style="width: 30rpx;height: 30rpx;position: absolute;margin-top: 8rpx;"
src="/Images/dingwei.png"></image>
<input wx:if="{{addressName==null}}" style="margin-left: 35rpx;" value="请选择位置"/>
<input wx:else name="specific" style="margin-left: 35rpx;" value="{{addressName}}"/>
</view>
点击事件
//获取用户定位授权,地图选点
getLocation: function () {
wx.getSetting({
success:res=>{
if(!res.authSetting['scope.userLocation']){
wx.authorize({
scope: 'scope.userLocation',
success:res=>{
},fail:res=>{
wx.showModal({
title: '提示',
content: '系统需要获取该您当前的定位,请确保您的位置授权已开启',
showCancel: false,
success: res=>{
if (res.confirm) {
wx.openSetting({
})
}
}
})
}
});
}
wx.chooseLocation({
success: res=>{
console.log(res)
if(res.address!='' && res.name!=''){
this.setData({
addressName: res.name,
addressDetail: res.address,
add:false
})
}
}
})
}
})
},