get-location.js 597 B

123456789101112131415161718192021222324252627282930313233
  1. const util = require('../../../../util/util.js')
  2. const formatLocation = util.formatLocation
  3. Page({
  4. onShareAppMessage() {
  5. return {
  6. title: '获取位置',
  7. path: 'page/API/pages/get-location/get-location'
  8. }
  9. },
  10. data: {
  11. hasLocation: false,
  12. },
  13. getLocation() {
  14. const that = this
  15. wx.getLocation({
  16. success(res) {
  17. console.log(res)
  18. that.setData({
  19. hasLocation: true,
  20. location: formatLocation(res.longitude, res.latitude)
  21. })
  22. }
  23. })
  24. },
  25. clear() {
  26. this.setData({
  27. hasLocation: false
  28. })
  29. }
  30. })