微信小程序 接入腾讯地图

微信小程序 接入腾讯地图两种接法

一、调用微信内置的腾讯地图,获取第三方软件

点击选择按钮获取第三方软件
在这里插入图片描述
这个相对简单,用的也比较多,配合以下两个API使用在这里插入图片描述
使用之前你需要在app.js中配置权限信息

"permission": {
    "scope.userLocation": {
      "desc": "你的位置信息将用于小程序位置接口的效果展示" 
    }
  },

在使用地图的页面使用

 chooseMap(){  
    var that = this
    let location = that.data.location
    wx.getLocation({
      type: 'gcj02', //返回可以用于wx.openLocation的经纬度
      success (res) { // 获取当前位置的经纬度
         const latitude = res.latitude
         const longitude = res.longitude
       // const latitude = location.lat
       // const longitude = location.lng
        wx.openLocation({
          latitude,
          longitude,
          name:'东莞市虎门镇白沙社区站北路1号',
          scale: 18
        })
      }
     })
  },

如果需要获取具体位置对应的经纬度或者经纬度对应的具体位置,需要接入腾讯位置服务 :https://lbs.qq.com/map/
具体步骤如下

  1. 注册 登入 点击控制台
    在这里插入图片描述 点击设置,配置如下,保存
    在这里插入图片描述
  2. 点击开发文档
    在这里插入图片描述下载核心类,放到项目当中,引入使用
    在这里插入图片描述
    在这里插入图片描述
    实现如下
routeMap() {
    var that  = this
    wx.getSetting({ // 获取当前的设置
    success(res){
    //这里判断是否有位置权限
      if (!res.authSetting['scope.userLocation']) {
          wx.showModal({
          title: '提示',
          content: '获取位置信息',
          success:function(res){
            if(res.confirm==false){
              return false
            }
            wx.openSetting({ // 打开设置
              success(res) {
              //如果再次拒绝则返回页面并提示
              if (!res.authSetting['scope.userLocation']) {
              wx.showToast({
              title: '此功能需获取位置信息,请重新设置',
              duration: 3000,
              icon: 'none'
              })
              } else {
              //允许授权,调用地图
                that.chooseMap()
                }
              }
            })
          }
          }) 
      } else {
      //如果有定位权限,调用地图
      that.chooseMap()
      }
    }
   })
  },
  chooseMap(){
    var that = this
    let location = that.data.location
    wx.getLocation({
      type: 'gcj02', //返回可以用于wx.openLocation的经纬度
      success (res) {
         const latitude = res.latitude
         const longitude = res.longitude
       // const latitude = location.lat
       // const longitude = location.lng
        wx.openLocation({
          latitude,
          longitude,
          name:'东莞市虎门镇白沙社区站北路1号',
          scale: 18
        })
      }
     })
  },

二、找到微信小程序
在这里插入图片描述在这里插入图片描述
然后进行相应配置开发…

未完待续。。。

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值