国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JavaScript > 正文

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

2019-11-19 18:39:52
字體:
來源:轉載
供稿:網友

微信小程序實例-獲取當前的地理位置、經緯度

微信小程序官方文檔

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

JS代碼

//index.js//獲取應用實例var app = getApp()Page({ data: {  motto: '示例小程序-獲取當前地理位、速度',  userInfo: {},  hasLocation:false,  location:{} }, //事件處理函數 bindViewTap: function() {  wx.navigateTo({   url: '../logs/logs'  }) }, onLoad: function () {  console.log('onLoad')  var that = this  //調用應用實例的方法獲取全局數據  app.getUserInfo(function(userInfo){   //更新數據   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>經度:{{location.longitude}}/n</text>  <text>緯度:{{location.latitude}}</text> </view></view>

運行效果

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

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 沙湾县| 柳河县| 保康县| 江川县| 维西| 攀枝花市| 赣榆县| 大名县| 时尚| 天台县| 六盘水市| 武宣县| 曲周县| 栾城县| 泸定县| 泊头市| 时尚| 疏勒县| 祁阳县| 砚山县| 中方县| 兖州市| 会理县| 随州市| 廉江市| 桃江县| 安义县| 买车| 花垣县| 保德县| 洛宁县| 长寿区| 门头沟区| 武宁县| 博兴县| 永清县| 阿图什市| 徐闻县| 滦平县| 台东市| 桃江县|