欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

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

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

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

微信小程序官方文檔

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

JS代碼

//index.js
//獲取應(yīng)用實(shí)例
var app = getApp()
Page({
 data: {
  motto: '示例小程序-獲取當(dāng)前地理位、速度',
  userInfo: {},
  hasLocation:false,
  location:{}
 },
 //事件處理函數(shù)
 bindViewTap: function() {
  wx.navigateTo({
   url: '../logs/logs'
  })
 },
 onLoad: function () {
  console.log('onLoad')
  var that = this
  //調(diào)用應(yīng)用實(shí)例的方法獲取全局?jǐn)?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>

運(yùn)行效果

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

相關(guān)文章

最新評論