第一步:app.josn中增加配置
"permission": {
"scope.userLocation": {
"desc": "你的位置信息将用于小程序位置接口的效果展示"
}
}
若不增加错误提示如下
第二步:wxml 中增加按钮
<button class='pop_btn' bindtap="getLocation" >获取Local</button>
第三步:js文件中增加
getLocation: function (e) {
wx.getLocation({
type: 'wgs84',
success: function (res) {
// console.log(res);
var latitude = res.latitude
var longitude = res.longitude
//弹框
wx.showModal({
title: '当前位置',
content: "纬度:" + latitude + ",经度:" + longitude,
})
}
})
}