miniprogram-demo/packageAPI/pages/get-location/get-location.js

34 lines
597 B
JavaScript
Raw Normal View History

2020-12-08 18:53:41 +08:00
const util = require('../../../utils/util.js')
const formatLocation = util.formatLocation
Page({
onShareAppMessage() {
return {
title: '获取位置',
path: 'packageAPI/pages/get-location/get-location'
}
},
data: {
hasLocation: false,
},
getLocation() {
const that = this
wx.getLocation({
success(res) {
console.log(res)
that.setData({
hasLocation: true,
location: formatLocation(res.longitude, res.latitude)
})
}
})
},
clear() {
this.setData({
hasLocation: false
})
}
})