1. 先在app.json添加配置
"permission": {
"scope.userLocation": {
"desc": "你的位置信息將用于小程序位置接口的效果展示"
}
},
"requiredPrivateInfos": [
"getLocation",
"chooseLocation"
],
2. 獲取定位權(quán)限,打開(kāi)地址選點(diǎn)文章來(lái)源:http://www.zghlxwxcb.cn/news/detail-617127.html
wx.showLoading({
title: '正在打開(kāi)',
mask:"true"
})
wx.getLocation({ //獲取位置權(quán)限
type: 'gcj02',
isHighAccuracy:true,
highAccuracyExpireTime:4000,
success(res) {
console.log(res)
var latitude = res.latitude // 緯度
var longitude = res.longitude // 經(jīng)度
wx.chooseLocation({ //打開(kāi)地址選點(diǎn)
latitude,
longitude,
success: function (data) {
console.log(data)
},
fail(res) {
console.log(res) // getLocation:fail the api need to be declared in the requiredPrivateInfos field in app.json
},
complete(){
wx.hideLoading()
}
})
},
fail(res) {
wx.hideLoading()
wx.openSetting() //用戶(hù)拒絕位置權(quán)限后打開(kāi)設(shè)置
}
})
3. 如果要打開(kāi)跳轉(zhuǎn)第三方地圖的內(nèi)置地圖文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-617127.html
wx.openLocation({
latitude, //經(jīng)度
longitude, //維度
name: '自提位置', // 位置名
address:"第十六屆可能安防監(jiān)控", // 要去的地址詳情說(shuō)明
scale: 1, // 地圖縮放級(jí)別,整形值,范圍從1~28。默認(rèn)為最大
success: function (data) {
console.log(data)
},
fail(res) {
console.log(res) // getLocation:fail the api need to be declared in the requiredPrivateInfos field in app.json
},
complete(){
wx.hideLoading()
}
})
到了這里,關(guān)于微信小程序獲取當(dāng)前位置與跳轉(zhuǎn)第三方地圖的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!