點選按鈕獲取當前位置

奮鬥年輕人發表於2017-08-07

wxml:

  <view class="classname" bindtap="openMap">測試微信小程式定位</view>



js:

  // 獲取地理位置

  openMap: function () {
    console.log(11111)
    wx.getLocation({
      type: 'gcj02', // 預設為 wgs84 返回 gps 座標,gcj02 返回可用於 wx.openLocation 的座標
      success: function (res) {
        // success
        console.log(22222)
        wx.openLocation({
          latitude: res.latitude, // 緯度,範圍為-90~90,負數表示南緯
          longitude: res.longitude, // 經度,範圍為-180~180,負數表示西經
          scale: 28, // 縮放比例          
        })
      }
    })
  },

相關文章