coordinate.nvue 5.4 KB

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