当前位置:   article > 正文

关于微信小程序获取位置和选择地图的注意事项_小程序选择地图位置限制区域

小程序选择地图位置限制区域

在小程序中使用位置和定位都要配置好app.json

//按相应的需求给,否则你就会报err



"requiredPrivateInfos": [
    "getLocation",
"onLocationChange",
"chooseLocation",
"chooseAddress"
]


    "permission": {
        "scope.userLocation": {
            "desc": "你的位置信息将用于测试"
        }
    },
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17

2.那么我们就能通过调用api实现我们想要的功能了

 wx.getLocation({
            type: 'wgs84',
            success: function (res) {
            //返回经纬度等,具体地址需求逆向编码
                console.log(res)
                }}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
wx.chooseLocation({
            success: res => {
            //返回经纬度城市编码等
                console.log(res)
                that.setData({
                    lon: res.longitude,
                    lat: res.latitude,
                    address: res.address
                })
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9

在这里插入图片描述

3.在最新的位置获取中还需要开发者到开发平台进行配置,可登录开发者账号进入开发管理一栏

本文内容由网友自发贡献,转载请注明出处:https://www.wpsshop.cn/w/IT小白/article/detail/968040
推荐阅读
相关标签
  

闽ICP备14008679号