choose-location.vue 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <template>
  2. <view>
  3. <page-head :title="title"></page-head>
  4. <view class="uni-padding-wrap">
  5. <view style="background:#FFFFFF; padding:40rpx;">
  6. <view class="uni-hello-text uni-center">当前位置信息</view>
  7. <block v-if="hasLocation === false">
  8. <view class="uni-h2 uni-center uni-common-mt">未选择位置</view>
  9. </block>
  10. <block v-if="hasLocation === true">
  11. <view class="uni-hello-text uni-center" style="margin-top:10px;">
  12. {{locationAddress}}
  13. </view>
  14. <view class="uni-h2 uni-center uni-common-mt">
  15. <text>E: {{location.longitude[0]}}°{{location.longitude[1]}}′</text>
  16. <text>\nN: {{location.latitude[0]}}°{{location.latitude[1]}}′</text>
  17. </view>
  18. </block>
  19. </view>
  20. <view class="uni-btn-v">
  21. <button type="primary" @tap="chooseLocation">选择位置</button>
  22. <button @tap="clear">清空</button>
  23. </view>
  24. </view>
  25. </view>
  26. </template>
  27. <script>
  28. import * as util from '../../../common/util.js'
  29. var formatLocation = util.formatLocation;
  30. export default {
  31. data() {
  32. return {
  33. title: 'chooseLocation',
  34. hasLocation: false,
  35. location: {},
  36. locationAddress: ''
  37. }
  38. },
  39. methods: {
  40. chooseLocation: function () {
  41. uni.chooseLocation({
  42. success: (res) => {
  43. this.hasLocation = true,
  44. this.location = formatLocation(res.longitude, res.latitude),
  45. this.locationAddress = res.address
  46. }
  47. })
  48. },
  49. clear: function () {
  50. this.hasLocation = false
  51. }
  52. }
  53. }
  54. </script>
  55. <style>
  56. .page-body-info {
  57. padding-bottom: 0;
  58. height: 440rpx;
  59. }
  60. </style>