微信小程序学习15--地图map组件的基本使用

地图

map组件的基本使用

<map longitude="113.324520" latitude="23.099994" scale="11"></map>
<button bindtap='handleShow'>显示当前位置</button>
<button type='primary' bindtap='handleOpen'>打开地图选择位置</button>

通过小程序API操作地图

  • 获取当前位置坐标(经纬度)wx.getLocation
  • 打开地图中的位置 wx.openLocation
  • 选中地图的位置并获取位置的详细信息 wx.chooseLocation
  handleOpen () {
    // 通过地图选择一个具体位置
    // 默认根据当前位置进行定位
    // 可以根据下面的列表提示选择具体某个位置
    wx.chooseLocation({
      // longitude: 116.3964,
      // latitude: 39.9093,
      success: function(res) {
        // 定位的详细数据:包括地址名称和经纬度信息
        console.log(res)
      }
    })
  },

  handleShow () {
    wx.getLocation({
      type: 'gcj02', //返回可以用于wx.openLocation的经纬度
      success(res) {
        const latitude = res.latitude
        const longitude = res.longitude
        wx.openLocation({
          latitude,
          longitude,
          scale: 18
        })
      }
    })
  },
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值