微信小程序实现简单定位功能,简单易读,获取经纬度信息
在pages下创建一个单页如location
local.js如下
getlaction:function(e){
var that = this
wx.getLocation({
type: 'wgs84',
success: function (res) {
console.log(res)
var latitude = res.latitude
var longitude = res.longitude
// var speed =res.speed
// var accuracy = res.accuracy
that.setData({
location:{
latitude: latitude,
longitude: longitude
}
})
}
})
},
location.wxml
<weui-input type='number' label="纬度" placeholder="{{location.latitude}}" icon="warn">
</weui-input>
<weui-input type='number' label="经度" placeholder="{{location.longitude}}" icon="success">
</weui-input>
<button form-type='submit' bindtap='getlaction'>获取当前位置</button>
最后在.js中添加一个模态框来显示经纬度:
wx.showModal({
title: '提示',
content: "纬度" + latitude + "经度" + longitude,
})