get-location.js 837 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. const util = require('../../../../util/util.js')
  2. const formatLocation = util.formatLocation
  3. Page({
  4. onShareAppMessage() {
  5. return {
  6. title: '获取位置',
  7. path: 'packageAPI/pages/location/get-location/get-location'
  8. }
  9. },
  10. data: {
  11. theme: 'light',
  12. hasLocation: false,
  13. },
  14. getLocation() {
  15. const that = this
  16. wx.getLocation({
  17. success(res) {
  18. console.log(res)
  19. that.setData({
  20. hasLocation: true,
  21. location: formatLocation(res.longitude, res.latitude)
  22. })
  23. }
  24. })
  25. },
  26. clear() {
  27. this.setData({
  28. hasLocation: false
  29. })
  30. },
  31. onLoad() {
  32. this.setData({
  33. theme: wx.getSystemInfoSync().theme || 'light'
  34. })
  35. if (wx.onThemeChange) {
  36. wx.onThemeChange(({theme}) => {
  37. this.setData({theme})
  38. })
  39. }
  40. }
  41. })