wx.getLocation
通过wx.getLocation
我们得到用户的经纬度位置。
使用wx.getLocation
之前需要简单的配置一下。因为获取用户地理位置的操作需要用户同意,所以我们在app.json
文件里面加上配置:
"permission": {
"scope.userLocation": {
"desc": "你的位置信息将用于小程序位置接口的效果展示"
}
复制代码
如下图:
之后参考官方文档使用:
// 获取用户地理位置
const res = await wx.getLocation({
type: "wgs84",
})