【微信小程序】地图map组件的使用,打开自动获取当前位置

map的使用

点击查看代码
<map latitude="{{latitude}}" longitude="{{longitude}}" markers="{{markers}}" bindmarkertap="markertap" />

页面启动后自动获取当前经纬度

点击查看代码
 data: {
      latitude: 0,
      longitude: 0,
	  }
 onReady: function () {
        wx.getLocation({
            type:"wgs84 ",
          success:(res)=>{
            // accuracy: 65
            // errMsg: "getLocation:ok"
            // horizontalAccuracy: 65
            // latitude: 34.26703
            // longitude: 108.9402
            // speed: -1
            // verticalAccuracy: 65
            this.setData({
                latitude:res.latitude,
                longitude:res.longitude
            })
          }
        })
    },

此操作必须在app.json中打开授权

点击查看代码
"permission": {

        "scope.userLocation": {
        
        "desc": "你的位置信息将用于小程序位置接口的效果展示"
        
        }
    },
posted @ 2022-04-16 10:04  一个大不刘blog  阅读(514)  评论(0编辑  收藏  举报