小程序 wx.getLocation比较难申请。可以使用wx.getFuzzyLocation 代替
"requiredPrivateInfos": ["getFuzzyLocation" ],
"permission": {
"scope.userFuzzyLocation": {
"desc": "你的位置信息将用于,订单创建"
}
}
如果不开通权限 本地测试没有问题。 提交代码上线 还是需要开通权限。

添加支持 "permission": {
"scope.userLocation": {
"desc": "你的位置信息将用于,订单创建"
}
},
"requiredPrivateInfos": ["getLocation"]

load_pos() {
var this_ = this;
wx.getLocation({
//type: 'gcj02', 这个参数 看一下干什么用的。
success: function (res) {
console.log("位置数据:", res);
this_.setData({
lng: res.longitude,
lat: res.latitude
})
},
fail(err) {
console.error('定位失败:', err.errMsg);
wx.showModal({
title: '权限提示',
content: '需要位置权限才能提供服务',
success(res) {
if (res.confirm) wx.openSetting();//跳转小程序设置界面 就是 位置和订阅消息 设置那个界面
}
});
}
})
},
//或者保存 经纬度到订单,我们可以通过 我们系统的腾讯地图 打开看看用户是哪里的。
如果用户拒绝了。那么需要用户再去 小程序设置开启。
check_pos() {
//如何用户 关闭位置,会跳转到 开启的设置界面=wx.openSetting()
wx.getSetting({
success(res) {
const authStatus = res.authSetting['scope.userLocation']
if (authStatus === false) {
console.log("重新授权")
wx.showModal({
title: '位置权限提示',
content: '需要您授权位置信息以提供周边服务',
success(res) {
if (res.confirm) wx.openSetting()
}
})
}
}
})
},

const QQMapWX = require('./qqmap-wx-jssdk.min.js')
const qqmapsdk = new QQMapWX({
key: '您的腾讯地图KEY' // 需替换实际key
})
export const getCityByLocation = (latitude, longitude) => {
return new Promise((resolve, reject) => {
qqmapsdk.reverseGeocoder({
location: { latitude, longitude },
success: res => resolve(res.result.address_component.city),
fail: err => reject(err)
})
})
}
import { getCityByLocation } from '../../utils/location'
Page({
onLoad() {
wx.getLocation({
type: 'gcj02',
success: async (res) => {
try {
const city = await getCityByLocation(res.latitude, res.longitude)
console.log('当前城市:', city)
} catch (e) {
console.error('解析失败', e)
}
}
})
}
})selectMap() {
var this_ = this;
wx.chooseLocation({
success: function(res) {
console.log(res);
console.log(res.address);
console.log(res.name);
console.log(res.latitude);
console.log(res.longitude);
},
})
} "permission": {
"scope.userLocation": {
"desc": "你的位置信息将用于,订单创建"
}
},
"requiredPrivateInfos": ["getLocation","chooseLocation"]

点击 定位图标 会重新回到你的当前位置。 上面还可以搜索地点。
dao_hang() {
//根据坐标打开地图
// 缩放18 好像没有效果 必须要手动放大
wx.openLocation({
latitude: Number(this.data.goods.lat),
longitude: Number(this.data.goods.lng),
scale: 18,
name: this.data.goods.name,//小明酒店
address: this.data.goods.address//地址可以自定义。
})
},
站长微信:xiaomao0055
站长QQ:14496453