coordinate.vue 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. <template>
  2. <view class="container">
  3. <view class="content">
  4. <text class="title-style">{{nowLocation.address}}</text>
  5. <map class="map" @tap="tap" @markertap="markertap" :latitude="nowLocation.latitude"
  6. :longitude="nowLocation.longitude" :markers="covers"
  7. :style="{height: nowMapIndex ? nintyPercentScreenHeight : seventyPercentScreenHeight,width:'750rpx,flex:1'}">
  8. </map>
  9. </view>
  10. <view class="bottom">
  11. <text class="bottom-text">
  12. {{longitude}},{{latitude}}
  13. </text>
  14. <text class="config" @click="config">确定</text>
  15. </view>
  16. </view>
  17. </template>
  18. <script>
  19. export default {
  20. data() {
  21. return {
  22. nowMapIndex: true,
  23. phoneHeight: '', //屏幕高
  24. phoneWidth: '', //屏幕宽
  25. detail: {
  26. longitude: '',
  27. latitude: ''
  28. },
  29. nowLocation: {
  30. longitude: '',
  31. latitude: '',
  32. address: '山海广场'
  33. },
  34. title: 'map',
  35. latitude: 39.909,
  36. longitude: 116.39742,
  37. covers: [{
  38. id: 0,
  39. latitude: 39.9085,
  40. longitude: 116.39747,
  41. iconPath: '../../../static/img/location.png',
  42. }]
  43. }
  44. },
  45. onReady() {
  46. },
  47. computed: { //计算
  48. nintyPercentScreenHeight() { //百分之九十的屏幕高
  49. if (this.phoneHeight !== '' && this.phoneWidth !== '') {
  50. return 750 / (this.phoneWidth) * (this.phoneHeight) * 0.9 + 'rpx'
  51. } else {
  52. return '1250rpx'
  53. }
  54. },
  55. seventyPercentScreenHeight() { //百分之七十的屏幕高
  56. if (this.phoneHeight !== '' && this.phoneWidth !== '') {
  57. return 750 / (this.phoneWidth) * (this.phoneHeight) * 0.7 + 'rpx'
  58. } else {
  59. return '1000rpx'
  60. }
  61. },
  62. },
  63. onLoad() {
  64. // 计算屏幕高度 ,宽度
  65. let _this = this;
  66. uni.getSystemInfo({
  67. success(res) {
  68. _this.phoneHeight = res.windowHeight;
  69. _this.phoneWidth = res.windowWidth
  70. }
  71. });
  72. this.getLocation()
  73. },
  74. methods: {
  75. getLocation() {
  76. let that = this;
  77. uni.getLocation({
  78. type: 'gcj02',
  79. geocode: true,
  80. success: function(res) {
  81. that.nowLocation.longitude = res.longitude
  82. that.nowLocation.latitude = res.latitude
  83. that.covers[0].longitude = res.longitude
  84. that.covers[0].latitude = res.latitude
  85. console.log('获取位置数据:', res);
  86. console.log('当前位置的经度:' + res.longitude);
  87. console.log('当前位置的纬度:' + res.latitude);
  88. //拼接当前定位回显地址
  89. // let _address = res.address
  90. // this.address = _address
  91. }
  92. });
  93. },
  94. tap(e) {
  95. this.longitude = e.detail.longitude;
  96. this.latitude = e.detail.latitude;
  97. console.log(this.longitude)
  98. console.log(this.latitude)
  99. },
  100. config() {
  101. uni.navigateTo({
  102. })
  103. }
  104. }
  105. }
  106. </script>
  107. <style scoped>
  108. .content {
  109. flex: 1;
  110. width: 750rpx;
  111. }
  112. .bottom {
  113. width: 750rpx;
  114. flex: 1;
  115. background: white;
  116. position: fixed;
  117. bottom: 54rpx;
  118. left: 0;
  119. right: 0;
  120. display: flex;
  121. flex-direction: row;
  122. justify-content: space-between;
  123. height: 84rpx;
  124. align-items: center;
  125. }
  126. .title-style {
  127. font-size: 32rpx;
  128. font-weight: 500;
  129. color: #333333;
  130. }
  131. .bottom-text{
  132. }
  133. .config{
  134. background:#22C572 ;
  135. }
  136. </style>