// //获取用户地理位置
// //先判断用户是否授权获取地理位置
// let that = this;
// wx.getSetting({
// success(res) {
// if (res.authSetting['scope.userLocation'] == false) {//如果没有授权地理位置
// wx.openSetting({
// success(res) {
// res.authSetting = {//打开授权位置页面,让用户自己开启
// "scope.userLocation": true
// }
// }
// })
// } else {
// //用户开启授权后可直接获取地理位置
// wx.authorize({
// scope: 'scope.userLocation',
// success() {
// //获取位置后相关操作
// wx.getLocation({
// type: 'wgs84',
// success (res) {
// console.log('纬度' + res.latitude)
// console.log('经度' + res.longitude)
// }
// })
// }
// })
// }
// }
// })
本文介绍如何在微信小程序中实现获取用户的地理位置信息。首先检查用户是否已授权地理位置权限,若未授权则引导用户进行授权设置。授权成功后,利用微信API获取用户的经纬度坐标。
571

被折叠的 条评论
为什么被折叠?



