coordinate.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. <template>
  2. <view class="container">
  3. <view class="content">
  4. <view @click='naviageToPage("/pages/grain_pulse/position/position")'>
  5. <image class='location' src="@/static/img/liangmai/icon_ditu.png" mode=""></image>
  6. <text class="title-style">{{position.name}}</text>
  7. </view>
  8. <map class="map" @tap="tap" @markertap="markertap" :latitude="position.latitude"
  9. :longitude="position.longitude" :markers="covers"
  10. :style="{height: nowMapIndex ? nintyPercentScreenHeight : seventyPercentScreenHeight,width:'750rpx,flex:1'}">
  11. </map>
  12. </view>
  13. <view class="bottom">
  14. <view class="bottom-left">
  15. <text class="bottom-content">经度:{{position.longitude}}</text>
  16. <text class="bottom-content">纬度:{{position.latitude}}</text>
  17. </view>
  18. <text class="config-btn" @click="config">确定</text>
  19. </view>
  20. </view>
  21. </template>
  22. <script>
  23. export default {
  24. data() {
  25. return {
  26. nowMapIndex: true,
  27. phoneHeight: '', //屏幕高
  28. phoneWidth: '', //屏幕宽
  29. position: {
  30. longitude: 116.39747,
  31. latitude: 39.9085,
  32. address: '未指定地点'
  33. },
  34. longitude: 116.39747,
  35. latitude: 39.9085,
  36. title: 'map',
  37. // covers: [{
  38. // id: 0,
  39. // latitude: 39.9085,
  40. // longitude: 116.39747,
  41. // iconPath: '../../../static/img/location.png',
  42. // }],
  43. covers: []
  44. }
  45. },
  46. onReady() {
  47. // 计算屏幕高度 ,宽度
  48. let _this = this;
  49. uni.getSystemInfo({
  50. success(res) {
  51. _this.phoneHeight = res.windowHeight;
  52. _this.phoneWidth = res.windowWidth
  53. }
  54. });
  55. },
  56. computed: { //计算
  57. nintyPercentScreenHeight() { //百分之百的屏幕高
  58. if (this.phoneHeight !== '' && this.phoneWidth !== '') {
  59. return 750 / (this.phoneWidth) * (this.phoneHeight) + 'rpx'
  60. } else {
  61. return '1250rpx'
  62. }
  63. },
  64. seventyPercentScreenHeight() { //百分之七十的屏幕高
  65. if (this.phoneHeight !== '' && this.phoneWidth !== '') {
  66. return 750 / (this.phoneWidth) * (this.phoneHeight) * 0.7 + 'rpx'
  67. } else {
  68. return '1000rpx'
  69. }
  70. },
  71. },
  72. onShow() {
  73. let that = this
  74. uni.getStorage({
  75. key: 'setPosition',
  76. success: (res) => {
  77. console.log(res.data)
  78. that.position = res.data
  79. that.position.longitude = res.data.location.split(',')[0];
  80. that.position.latitude = res.data.location.split(',')[1];
  81. console.log(that.position.longitude)
  82. console.log(that.position.latitude)
  83. // uni.removeStorage({
  84. // key: 'setLocaltion'
  85. // })
  86. },
  87. })
  88. },
  89. onLoad() {
  90. // this.getLocation()
  91. },
  92. methods: {
  93. naviageToPage(item) {
  94. uni.setStorage({
  95. key: 'setPositionType',
  96. data:{type:1},
  97. success: function(res) {
  98. console.log(item)
  99. uni.navigateTo({
  100. url: item
  101. })
  102. }
  103. });
  104. },
  105. tap(e) {
  106. var that = this
  107. let newmarker =[];
  108. var id=1;
  109. // this.position.longitude = e.detail.longitude;
  110. // this.position.latitude = e.detail.latitude;
  111. // console.log(this.longitude)
  112. // console.log(this.latitude)
  113. // let maker= {
  114. // id: id++,
  115. // latitude: this.position.latitude,
  116. // longitude:e.detail.longitude,
  117. // iconPath: '../../../static/img/location.png',
  118. // }
  119. // newmarker.push(maker)
  120. // this.covers = newmarker
  121. var lnglat = e.detail.longitude+','+e.detail.latitude
  122. console.log("lnglat",lnglat)
  123. let parameters = {
  124. key: 'dd701d394d116b50268dc16470ddd615',
  125. location: lnglat
  126. }
  127. uni.request({
  128. url: 'https://restapi.amap.com/v3/geocode/regeo?parameters',
  129. data: parameters,
  130. success: (res) => {
  131. that.position=res.data.regeocode.addressComponent
  132. console.log(res.data.regeocode.addressComponent)
  133. that.position.longitude = res.data.regeocode.addressComponent.streetNumber.location.split(',')[0];
  134. that.position.latitude = res.data.regeocode.addressComponent.streetNumber.location.split(',')[1];
  135. let maker= {
  136. id: id++,
  137. latitude: that.position.latitude,
  138. longitude:that.position.longitude,
  139. iconPath: '../../../static/img/location.png',
  140. }
  141. newmarker.push(maker)
  142. that.covers = newmarker
  143. }
  144. });
  145. },
  146. config() {
  147. // console.log("this.position",this.position)
  148. // this.position.selectLocation = this.position.longitude+","+this.position.latitude
  149. // console.log("this.position",this.position)
  150. uni.navigateTo({
  151. url:"/pages/grain_pulse/enter?position="+JSON.stringify(this.position)
  152. })
  153. }
  154. }
  155. }
  156. </script>
  157. <style scoped>
  158. .content {
  159. flex: 1;
  160. width: 750rpx;
  161. }
  162. .bottom {
  163. position: fixed;
  164. bottom: 54rpx;
  165. left: 25rpx;
  166. right: 0;
  167. width:700rpx;
  168. background: white;
  169. flex-direction: row;
  170. flex: 1;
  171. justify-content: space-between;
  172. align-items: center;
  173. padding: 22rpx 20rpx 22rpx 49rpx;
  174. border-radius: 20rpx;
  175. }
  176. .title-style {
  177. font-size: 32rpx;
  178. font-weight: 500;
  179. color: #333333;
  180. }
  181. .config-btn{
  182. width: 144rpx;
  183. height: 67rpx;
  184. line-height: 67rpx;
  185. background: #22C572;
  186. border-radius: 10rpx;
  187. color: white;
  188. text-align: center;
  189. font-size: 28rpx;
  190. }
  191. .bottom-content{
  192. font-size: 28rpx;
  193. }
  194. .location {
  195. width: 27rpx;
  196. height: 31rpx;
  197. }
  198. </style>