小程序实现地图导航功能


源码下载链接

app.json获取导航授权信息

1.desc授权导航是弹窗文字

 "permission": {
    "scope.userLocation": {
      "desc": "导航需要" 
    }
  },

wxml文件中命令

map组件基本命令以及作用

1.bindmarkertap=“biaoji"标记点击的回调函数
2.data-mark=”“标记点击携带的数据
3.latitude=”“纬度
4. longitude=”“经度
5. markers=”"标记基本参数(通过调用js文件中data来实现)
6. scale="17"地图缩放比例

<map class="map" bindmarkertap="biaoji" data-mark="{{markers[0]}}" latitude="{{latitude}}" longitude="{{longitude}}" markers="{{markers}}" scale="17"></map>

js文件中命令

1.在data中设置地图界面显示的经纬度

2.在data中设置标记点宽高经纬度

3.标记点点击的回调函数

getLocation获取当前自己经纬度

openLocation跳转腾讯地图并查看导航

未授权地理地理位置的处理

1.showModal弹窗请求授权
2.openSetting跳转在小程序中设置页面

  data: {
    latitude: 31.462191, //纬度
    longitude: 104.75028, //经度
    markers: [{
      id: 1,
      width: 50, //标记宽
      height: 50, //标记高
      latitude: 31.462191,
      longitude: 104.75028,
    }]
  },
  biaoji(e) {
    console.log("标记目的地点击", e)
    wx.getLocation({//获取当前地址信息
      type: 'wgs84',
      success(res) {
        const latitude = res.latitude
        const longitude = res.longitude
        const speed = res.speed
        const accuracy = res.accuracy
        wx.openLocation({//跳转腾讯地图查看并可以进行导航
          latitude: 31.462191,
          longitude: 104.75028,
        })
      },fail(res){//未授权地理位置处理
        wx.showModal({
          title: '请授权',
          content: '若未授权地理位置,您将不能正常使用导航功能',
          confirmText:"授权",
          success (res) {
            if (res.confirm) {
              console.log('用户点击确定')
              wx.openSetting({//跳转设置授权界面
              })
            } else if (res.cancel) {
              console.log('用户点击取消')
            }
          }
        })
      }  
    })
  }```

  • 5
    点赞
  • 32
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

陈阳羽

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值