choose-location.js 907 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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/choose-location/choose-location'
  8. }
  9. },
  10. data: {
  11. theme: 'light',
  12. hasLocation: false,
  13. },
  14. chooseLocation() {
  15. const that = this
  16. wx.chooseLocation({
  17. success(res) {
  18. console.log(res)
  19. that.setData({
  20. hasLocation: true,
  21. location: formatLocation(res.longitude, res.latitude),
  22. locationAddress: res.address
  23. })
  24. }
  25. })
  26. },
  27. clear() {
  28. this.setData({
  29. hasLocation: false
  30. })
  31. },
  32. onLoad() {
  33. this.setData({
  34. theme: wx.getSystemInfoSync().theme || 'light'
  35. })
  36. if (wx.onThemeChange) {
  37. wx.onThemeChange(({theme}) => {
  38. this.setData({theme})
  39. })
  40. }
  41. }
  42. })