一、如何获取当前位置信息
先在wxml中,写一个按钮,绑定一个getLocation的方法,如:
<button bindtap="getLocation">获取位置</button>
然后在js中,写getLocation方法,此方法在体验版的小程序中可以找到
getLocation: function () {
wx.getLocation({
type: 'wgs84',
success: (res)=> {
var latitude = res.latitude
var longitude = res.longitude
var speed = res.speed
var accuracy = res.accuracy
console.log(latitude, longitude)
wx.showModal({
title: '当前位置',
content: '纬度:' + latitude+'经度:'+longitude,
success: function (res) {
if (res.confirm) {
console.log('用户点击确定')
}
}
})
}
})
当点击按钮式,会弹出你当前的地理坐标。