-
微信小程序 ->开发设置->接口设置->开通 wx.getLocation
-
申请理由:应当前业务涉及周边服务推荐需要,需获取用户地理位置信息
-
调试基础库:2.24.4
-
在app.json中添加
“requiredPrivateInfos”:[
“getLocation”
],
-
页面使用:
wx.getLocation({
type: 'gcj02',
success (res) {
console.log('经纬度',res)
const latitude = res.latitude
const longitude = res.longitude
wx.setStorageSync('latitude', latitude)
wx.setStorageSync('longitude', longitude)
},
fail(res){
console.log('获取经纬度失败',res)
}
})