亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

微信小程序 獲取當前地理位置和經(jīng)緯度實例代碼

 更新時間:2016年12月05日 14:51:02   作者:韓天偉  
這篇文章主要介紹了微信小程序 獲取當前地理位置和經(jīng)緯度實例代碼的相關(guān)資料,這里附有實例代碼,及實現(xiàn)效果圖,需要的朋友可以參考下

微信小程序?qū)嵗?獲取當前的地理位置、經(jīng)緯度

微信小程序官方文檔

https://mp.weixin.qq.com/debug/wxadoc/dev/api/location.html

JS代碼

//index.js
//獲取應用實例
var app = getApp()
Page({
 data: {
  motto: '示例小程序-獲取當前地理位、速度',
  userInfo: {},
  hasLocation:false,
  location:{}
 },
 //事件處理函數(shù)
 bindViewTap: function() {
  wx.navigateTo({
   url: '../logs/logs'
  })
 },
 onLoad: function () {
  console.log('onLoad')
  var that = this
  //調(diào)用應用實例的方法獲取全局數(shù)據(jù)
  app.getUserInfo(function(userInfo){
   //更新數(shù)據(jù)
   that.setData({
    userInfo:userInfo
   })
  }),
   wx.getLocation( {
   success: function( res ) {
    console.log( res )
    that.setData( {
     hasLocation: true,
     location: {
      longitude: res.longitude,
      latitude: res.latitude
     }
    })
   }
  })
 }
})

index.wxml

<!--index.wxml-->
<view class="container">
 <view bindtap="bindViewTap" class="userinfo">
  <image class="userinfo-avatar" src="{{userInfo.avatarUrl}}" background-size="cover"></image>
  <text class="userinfo-nickname">{{userInfo.nickName}}</text>
 </view>
 <view class="usermotto">
  <!-- <text class="user-motto">{{motto}}\n</text>-->
  <text>經(jīng)度:{{location.longitude}}\n</text>
  <text>緯度:{{location.latitude}}</text>
 </view>
</view>

運行效果

感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!

相關(guān)文章

最新評論