index - 副本.nvue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559
  1. <template>
  2. <div>
  3. <image class="imgBj" src="@/static/images/home/indexBackground.png">
  4. <!-- <u-button @click="submit" class="buttonLang commonMb">确认选择</u-button> -->
  5. </image>
  6. <h1>11111111</h1>
  7. <!-- <view class="map">
  8. <map id="map" ref="map" :polyline="polyline" :scale="scale" :style="{height: windowHeight}"
  9. :markers="markers" :polygons="polygons" :latitude="latitude" :longitude="longitude" @tap="tap"
  10. :show-location="true" @markertap="markertap" @poitap="poitap" enable-rotate enable-overlooking
  11. enable-poi>
  12. </map>
  13. <div style="display: flex;">
  14. <button @click="path()"> 绘制轨迹</button>
  15. <button @click="graph()"> 绘制矩形</button>
  16. </div>
  17. </view> -->
  18. <button>确认选择</button>
  19. </div>
  20. </template>
  21. <script>
  22. // const fUN_AmapLocation = uni.requireNativePlugin('FUN-AmapLocation');
  23. var _this;
  24. export default {
  25. data() {
  26. return {
  27. barHeight: null, //动态高度初始值
  28. windowHeight: null,
  29. needBack: true,
  30. latitude: '39.997761',
  31. longitude: '116.478928',
  32. value: '1223',
  33. markers: [{
  34. latitude: 39.909,
  35. longitude: 116.39742,
  36. width: 60,
  37. height: 60,
  38. rotate: 90,
  39. iconPath: 'https://hellouniapp.dcloud.net.cn/static/location.png'
  40. }, ],
  41. polygons: [{
  42. points: [],
  43. fillColor: '#BB0000DD',
  44. width: 5,
  45. strokeColor: "blue", //描边颜色
  46. strokeWidth: 4, //描边宽度
  47. zIndex: 100, //层级
  48. }],
  49. polyline: [{
  50. points: [],
  51. arrowLine: true,
  52. }],
  53. scale: 16,
  54. title: '',
  55. msg: '',
  56. msg2: '',
  57. intTime: 0,
  58. maxTime: 0,
  59. minTime: 0,
  60. totalTime: 0,
  61. initTime: new Date().getTime(),
  62. lastTime: 0,
  63. nowtime: 0,
  64. locTime: 0,
  65. reTime: 0,
  66. count: 0,
  67. errorCount: 0,
  68. }
  69. },
  70. computed: {},
  71. onLoad() {
  72. this.fitNav()
  73. this.getLocation();
  74. // fUN_AmapLocation.once({}, result => {
  75. // console.log('====fUN_AmapLocation::8秒后单次定位示例====', JSON.stringify(result));
  76. // // _this.msg = JSON.stringify(result);
  77. // });
  78. },
  79. methods: {
  80. tap(e) {
  81. console.log(e);
  82. },
  83. getData(latitude, longitude) {
  84. let _this = this;
  85. // // 为做测试,我是对 polyline 点集合中最后一个点进行相对加一个数,让它有效果出来
  86. // let latitude = _this.polyline[0].points[_this.polyline[0].points.length - 1].latitude + 0.0001;
  87. // let longitude = _this.polyline[0].points[_this.polyline[0].points.length - 1].longitude + 0.0001;
  88. // 将新的点结构起来
  89. let dat = {
  90. latitude,
  91. longitude
  92. };
  93. // 把原 polyline 的数据复制一份
  94. let polyline_obj = JSON.parse(JSON.stringify(_this.polyline[0]));
  95. // 然后将新的点放到复制之后的这个对象里面去
  96. polyline_obj.points.push(dat);
  97. // 重组对象,让它和原 polyline 的数据结构一样
  98. let polyline = [polyline_obj, ];
  99. // 然后整体再赋值给原 polyline
  100. _this.polyline = polyline;
  101. // 最后修改中心经纬度
  102. _this.latitude = latitude;
  103. _this.longitude = longitude;
  104. },
  105. //绘制轨迹
  106. path() {
  107. let polyline_obj = JSON.parse(JSON.stringify(this.polyline[0]));
  108. polyline_obj.points = [{
  109. "longitude": 116.478928,
  110. "latitude": 39.997761
  111. },
  112. {
  113. "longitude": 116.478907,
  114. "latitude": 39.998422
  115. },
  116. {
  117. "longitude": 116.479384,
  118. "latitude": 39.998546
  119. },
  120. {
  121. "longitude": 116.481053,
  122. "latitude": 39.998204
  123. },
  124. {
  125. "longitude": 116.481793,
  126. "latitude": 39.997868
  127. },
  128. {
  129. "longitude": 116.482898,
  130. "latitude": 39.998217
  131. },
  132. {
  133. "longitude": 116.483789,
  134. "latitude": 39.999063
  135. },
  136. {
  137. "longitude": 116.484674,
  138. "latitude": 39.999844
  139. }
  140. ]
  141. let polyline = [polyline_obj, ];
  142. // 然后整体再赋值给原 polyline
  143. this.polyline = polyline;
  144. this.longitude = "116.478928"
  145. this.latitude = "39.997761"
  146. },
  147. //绘制矩形
  148. graph() {
  149. let polygons_obj = JSON.parse(JSON.stringify(this.polygons[0]));
  150. polygons_obj.points = [{ // 右上
  151. latitude: 30.264786,
  152. longitude: 120.10775,
  153. }, { // 右下
  154. latitude: 30.268786,
  155. longitude: 120.10775,
  156. },
  157. { // 左下
  158. latitude: 30.268786,
  159. longitude: 120.10465,
  160. }, { // 左上
  161. latitude: 30.264786,
  162. longitude: 120.10575,
  163. }
  164. ]
  165. let polygons = [polygons_obj, ];
  166. // 然后整体再赋值给原 polygons
  167. this.polygons = polygons;
  168. console.log('矩形重画完毕')
  169. this.longitude = "120.10775"
  170. this.latitude = "30.264786"
  171. },
  172. //点击选择地址
  173. addressChoose() {
  174. uni.chooseLocation({
  175. success: (res) => {
  176. // latitude:this.latitude,
  177. // longitude:this.longitude,
  178. // console.log('位置名称:' + res.name);
  179. // console.log('详细地址:' + res.address);
  180. // console.log('纬度:' + res.latitude);
  181. // console.log('经度:' + res.longitude);
  182. this.longitude = res.longitude
  183. this.latitude = res.latitude
  184. this.markeMove()
  185. }
  186. });
  187. },
  188. markeMove() {
  189. this.$nextTick(() => {
  190. this.scale = 16
  191. // 更新Markers点
  192. uni.createMapContext("map", this).translateMarker({
  193. markerId: 'myId',
  194. destination: {
  195. latitude: this.latitude,
  196. longitude: this.longitude
  197. },
  198. });
  199. })
  200. },
  201. // 获取手机信息及位置
  202. fitNav() {
  203. // 获取手机信息
  204. let info = uni.getSystemInfoSync()
  205. //顶部高度
  206. this.barHeight = info.statusBarHeight
  207. this.windowHeight = info.windowHeight
  208. console.log('尺寸', info)
  209. },
  210. //返回
  211. back() {
  212. uni.navigateBack({
  213. delta: 1
  214. })
  215. },
  216. //保存
  217. saveBtn() {
  218. console.log('保存')
  219. },
  220. //获取当前位置
  221. getLocation() {
  222. uni.getLocation({
  223. type: 'gcj02',
  224. success: (res) => {
  225. console.log('当前位置的经度:' + res.longitude);
  226. console.log('当前位置的纬度:' + res.latitude);
  227. this.longitude = res.longitude
  228. this.latitude = res.latitude
  229. // this.move()
  230. this.markeMove()
  231. }
  232. });
  233. },
  234. //移动到此位置
  235. move() {
  236. this.$nextTick(() => {
  237. this.scale = 16
  238. uni.createMapContext("map", this).moveToLocation({
  239. longitude: this.longitude,
  240. latitude: this.latitude,
  241. });
  242. })
  243. },
  244. //放大
  245. add() {
  246. uni.createMapContext("map", this).getScale({
  247. success: (res) => {
  248. // console.log('返回值', res);
  249. this.scale = res.scale
  250. if (this.scale < 20) {
  251. this.scale += 1
  252. }
  253. }
  254. })
  255. },
  256. //缩小
  257. sub() {
  258. uni.createMapContext("map", this).getScale({
  259. success: (res) => {
  260. // console.log('返回值', res);
  261. this.scale = res.scale
  262. if (this.scale > 3) {
  263. this.scale -= 1
  264. }
  265. }
  266. })
  267. },
  268. //标记点的点击事件
  269. markertap(e) {
  270. // console.log('点击markertap', e)
  271. uni.openLocation({
  272. latitude: this.latitude,
  273. longitude: this.longitude,
  274. success: function() {
  275. // console.log('success');
  276. }
  277. });
  278. },
  279. //地图的点击事件
  280. poitap(e) {
  281. // console.log('点击maps', e.detail)
  282. this.longitude = e.detail.longitude
  283. this.latitude = e.detail.latitude
  284. this.markeMove()
  285. },
  286. //打开应用设置页
  287. settingUp() {
  288. fUN_AmapLocation.openSetting(function(result) {
  289. });
  290. },
  291. // 获取权限
  292. permission() {
  293. _this = this;
  294. console.log('获取权限');
  295. fUN_AmapLocation.permission({}, result => {
  296. console.log('====fUN_AmapLocation定位====', JSON.stringify(result));
  297. if (result.code === 0) {
  298. if (result.flag === true && result.flag_br === true) {
  299. _this.battery()
  300. } else {
  301. uni.showModal({
  302. title: '提醒',
  303. showCancel: true,
  304. content: '请在权限-位置信息中选择始终允许',
  305. success: function(res) {
  306. if (res.confirm) {
  307. _this.settingUp();
  308. } else if (res.cancel) {
  309. // alert('用户点击取消');
  310. }
  311. }
  312. })
  313. }
  314. }
  315. });
  316. },
  317. //开启电池优化
  318. battery() {
  319. let _that = this;
  320. //检测是否忽略电池优化(简单解释:开启电池优化,会干掉应用)
  321. fUN_AmapLocation.isIgnoringBatteryOptimizations(function(result) { //SDK>=23,否则返回不支持
  322. if (result.code === 0) {
  323. if (result.flag === true) {
  324. console.log('====忽略电池优化====')
  325. _that.count = 0;
  326. _that.start();
  327. _that.openWakeLock();
  328. } else {
  329. // 申请忽略电池优化(如果已加入电池优化的白名单 则进入系统电池优化页面,若未加入则弹窗申请。)
  330. fUN_AmapLocation.requestIgnoreBatteryOptimizations(function(result) {
  331. console.log(result)
  332. console.log('====申请电池优化====')
  333. });
  334. }
  335. }
  336. })
  337. },
  338. //打开屏幕唤醒
  339. openWakeLock() {
  340. //1台华为[鸿蒙],2台小米(米6[安卓9]、米11Ultra[安卓11])使用的10分测试的。
  341. fUN_AmapLocation.openWakeLock({
  342. time: 5
  343. }, function(result) {
  344. console.log('====被唤醒了====', JSON.stringify(result))
  345. // if(result.code===0)
  346. // {
  347. // }
  348. });
  349. //参数 time:间隔时间,单位:分,建议5-10。具体看业务
  350. },
  351. //关闭屏幕唤醒
  352. colseWakeLock() {
  353. fUN_AmapLocation.colseWakeLock(function(result) {
  354. console.log('====结束被唤醒了====', JSON.stringify(result))
  355. });
  356. },
  357. // 结束持续定位
  358. end() {
  359. let _taht = this;
  360. fUN_AmapLocation.stop({}, result => {
  361. _taht.colseWakeLock();
  362. // console.log('====fUN_AmapLocation定位stop====', JSON.stringify(result));
  363. });
  364. },
  365. //开启持续定位
  366. start() {
  367. console.log('==fUN_AmapLocation==:开启定位');
  368. fUN_AmapLocation.start({
  369. intervalTime: 3000,
  370. isReport: false, //false 以下可以不传
  371. reportInterval: 6, //每定位几次进行上传
  372. url: 'http://192.168.0.66/fun/open/test_json.do', //上传URL
  373. params: {
  374. a: 1,
  375. B: '测试',
  376. c: true
  377. }, //上传的自定义参数,如加入其它数据
  378. headers: {
  379. a: '123',
  380. B: 'abcd'
  381. } //request headers 参数 比如加上token
  382. },
  383. result => {
  384. console.log(result);
  385. console.log('====fUN_AmapLocation定位====', JSON.stringify(result));
  386. if (result.code === 0) {
  387. _this.count++;
  388. _this.getData(result.latitude, result.longitude)
  389. } else {
  390. _this.errorCount++;
  391. }
  392. var now = new Date();
  393. _this.nowtime = now.getTime();
  394. _this.intTime = _this.nowtime - _this.lastTime;
  395. if (_this.intTime > _this.maxTime && _this.lastTime != 0) {
  396. _this.maxTime = _this.intTime;
  397. }
  398. if (_this.intTime < _this.minTime) {
  399. _this.minTime = _this.intTime;
  400. }
  401. _this.totalTime = _this.lastTime - _this.initTime;
  402. _this.lastTime = _this.nowtime;
  403. _this.msg2 = now.getHours() + ':' + now.getMinutes() + ':' + now.getSeconds();
  404. _this.msg = JSON.stringify(result);
  405. _this.reTime = result.now;
  406. _this.locTime = result.time;
  407. }
  408. );
  409. }
  410. }
  411. }
  412. </script>
  413. <style scoped>
  414. .my-top-nvue {
  415. width: 750rpx;
  416. height: 88rpx;
  417. background-color: #ffffff;
  418. display: flex;
  419. flex-direction: row;
  420. justify-content: space-between;
  421. align-items: center;
  422. padding: 0 30rpx;
  423. /* border-width: 1px;
  424. border-style: solid;
  425. border-color: red; */
  426. }
  427. .my-top-nvue-back {
  428. width: 20rpx;
  429. height: 35rpx;
  430. }
  431. .my-top-nvue-words {
  432. font-size: 36rpx;
  433. color: #323232;
  434. }
  435. .my-top-nvue-save {
  436. font-size: 30rpx;
  437. color: #42c2a4;
  438. }
  439. .cover-view-input {
  440. width: 650rpx;
  441. height: 90rpx;
  442. background-color: #ffffff;
  443. border-radius: 10rpx;
  444. position: absolute;
  445. top: 50rpx;
  446. left: 50rpx;
  447. display: flex;
  448. flex-direction: row;
  449. align-items: center;
  450. padding: 0 20rpx;
  451. }
  452. .searchImg {
  453. width: 26rpx;
  454. height: 26rpx;
  455. /* border-width: 1px;
  456. border-style: solid;
  457. border-color: red; */
  458. }
  459. .searchWords {
  460. margin-left: 15rpx;
  461. /* border-width: 1px;
  462. border-style: solid;
  463. border-color: red; */
  464. }
  465. .searchWords-text {
  466. font-size: 28rpx;
  467. color: #969696;
  468. }
  469. .cover-view-loca {
  470. width: 90rpx;
  471. height: 90rpx;
  472. background-color: #ffffff;
  473. border-radius: 20rpx;
  474. position: absolute;
  475. bottom: 60rpx;
  476. left: 60rpx;
  477. display: flex;
  478. align-items: center;
  479. justify-content: center;
  480. }
  481. .cover-loca-image {
  482. width: 40rpx;
  483. height: 40rpx;
  484. }
  485. .cover-view-plus {
  486. width: 90rpx;
  487. height: 180rpx;
  488. background-color: #ffffff;
  489. border-radius: 20rpx;
  490. position: absolute;
  491. bottom: 60rpx;
  492. right: 60rpx;
  493. display: flex;
  494. align-items: center;
  495. justify-content: center;
  496. }
  497. .plus-btn {
  498. width: 90rpx;
  499. height: 90rpx;
  500. display: flex;
  501. align-items: center;
  502. justify-content: center;
  503. }
  504. .btn-line {
  505. width: 90rpx;
  506. height: 1rpx;
  507. border-width: 1px;
  508. border-style: solid;
  509. border-color: #ececec;
  510. }
  511. .btn-img {
  512. width: 36rpx;
  513. height: 36rpx;
  514. }
  515. .mvBj {
  516. border: aqua solid 1px;
  517. }
  518. .imgBj {
  519. position: absolute;
  520. width: 100%;
  521. height: 100%;
  522. left: 0;
  523. top: 0;
  524. right: 0;
  525. bottom: 0;
  526. z-index: -999;
  527. }
  528. </style>