微信小程序 獲取當(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)文章
詳解Three.js?場景中如何徹底刪除模型和性能優(yōu)化
這篇文章主要為大家介紹了詳解Three.js?場景中如何徹底刪除模型和性能優(yōu)化,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-04-04
gulp-font-spider實(shí)現(xiàn)中文字體包壓縮實(shí)踐
這篇文章主要為大家介紹了gulp-font-spider實(shí)現(xiàn)中文字體包壓縮實(shí)踐詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-03-03
微信小程序(應(yīng)用號)簡單實(shí)例應(yīng)用及實(shí)例詳解
這篇文章主要介紹了微信小程序(應(yīng)用號)簡單實(shí)例應(yīng)用的相關(guān)資料,需要的朋友可以參考下2016-09-09

