微信小程序 获取GPS经纬度坐标以及Canvas绘图

版权声明:本文为博主原创文章,未经博主允许不得转载,如文章对您有帮助,请页面左侧随意打赏。 https://blog.csdn.net/smartsmile2012/article/details/83615223
Page({

  /**
   * 页面的初始数据
   */
  data: {
    storageData: []
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
  },

  // 测试
  testBtnClick: function() {
    // 绘图
    const ctx = wx.createCanvasContext('myCanvas')

    ctx.setFillStyle('red')
    ctx.fillRect(10, 10, 150, 100)
    ctx.draw()
    ctx.fillRect(50, 50, 150, 100)
    ctx.draw(true)  //保持上次绘画效果
    ctx.setFillStyle('blue')
    ctx.fillRect(100, 100, 150, 100)
    ctx.draw(true)  //保持上次绘画效果

    // 地图
    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,
          longitude,
          scale: 28
        })
      }
    })
  }
})
<view class='viewCanvas'>
<canvas class='viewCanvas-item'  canvas-id='myCanvas'></canvas>
</view>

<view><button bindtap='testBtnClick'>测试</button></view>

猜你喜欢

转载自blog.csdn.net/smartsmile2012/article/details/83615223