choose-location.js 667 B

12345678910111213141516171819202122232425262728293031323334
  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/choose-location/choose-location'
  8. }
  9. },
  10. data: {
  11. hasLocation: false,
  12. },
  13. chooseLocation() {
  14. const that = this
  15. wx.chooseLocation({
  16. success(res) {
  17. console.log(res)
  18. that.setData({
  19. hasLocation: true,
  20. location: formatLocation(res.longitude, res.latitude),
  21. locationAddress: res.address
  22. })
  23. }
  24. })
  25. },
  26. clear() {
  27. this.setData({
  28. hasLocation: false
  29. })
  30. }
  31. })