关于点击没反应
manifest.json 检查是否添加了对应的权限
/* 小程序特有相关 */"mp-weixin" : {"appid" : "wxc481f10754f1d9df","setting" : {"urlCheck" : false,"es6" : true,"postcss" : true,"minified" : true},"usingComponents" : true,"permission" : {"scope.userLocation" : {"desc" : "你的位置信息将用于小程序位置接口的效果展示" // 高速公路行驶持续后台定位}},"lazyCodeLoading" : "requiredComponents","requiredPrivateInfos" : [ "chooseLocation", "getLocation", "chooseAddress","openLocation" ]},
微信开发者权限是否开启
获取对应权限
uni.authorize({scope: 'scope.userLocation',fail: (res) => {uni.showModal({title: '使用该功能必须允许位置服务,是否重新授权?',showCancel: false,success: ({ confirm }) => {if (confirm) {uni.openSetting({success() {//重新获取权限并判断console.log('开启权限成功')},fail() {console.log('开启权限失败')},})}},})},success: () => {//重新获取权限并判断},
})
uni.openLocation({latitude: Number(item.get_addr.get_addr_lat), //folat类型longitude: Number(item.get_addr.get_addr_lng),name: item.get_addr.get_addr,address:'详细地址',success: function() {console.log('success');}});
openLocation
chooseLocation
uni.chooseLocation({success: (res) => {if (res.errMsg === 'chooseLocation:ok') {console.log('位置名称:' + res.name);console.log('详细地址:' + res.address);console.log('纬度:' + res.latitude);console.log('经度:' + res.longitude);}}
});
打开地图选择地址
h5 需要配置 相关地图 key
app 使用高德地图,打包才能看到效果
getLocation
直接获取当前位置
uni.getLocation({type: 'wgs84',success:(res)=>{console.log("获取成功",res)resolve(res)},fail:(err)=>{console.log("获取失败",err)reject(err)}})