Yansen 1年前
父节点
当前提交
7c96ade2aa
共有 5 个文件被更改,包括 46 次插入0 次删除
  1. 1
    0
      package.json
  2. 1
    0
      src/components/map/index.jsx
  3. 5
    0
      src/index.html
  4. 34
    0
      src/utils/map.js
  5. 5
    0
      yarn.lock

+ 1
- 0
package.json 查看文件

52
     "@zjxpcyc/react-tiny-store": "^2.0.1",
52
     "@zjxpcyc/react-tiny-store": "^2.0.1",
53
     "echarts": "^5.4.1",
53
     "echarts": "^5.4.1",
54
     "echarts-for-weixin": "^1.0.2",
54
     "echarts-for-weixin": "^1.0.2",
55
+    "gcoord": "^1.0.6",
55
     "md5": "^2.3.0",
56
     "md5": "^2.3.0",
56
     "postcss-modules": "^6.0.0",
57
     "postcss-modules": "^6.0.0",
57
     "react": "^18.0.0",
58
     "react": "^18.0.0",

+ 1
- 0
src/components/map/index.jsx 查看文件

3
 import { View, Map } from "@tarojs/components";
3
 import { View, Map } from "@tarojs/components";
4
 import { Icon, Loading } from "@antmjs/vantui";
4
 import { Icon, Loading } from "@antmjs/vantui";
5
 import { getLocation, h5GetLocation } from "@/utils/authorize";
5
 import { getLocation, h5GetLocation } from "@/utils/authorize";
6
+// import { getLocation } from "@/utils/map";
6
 import iconPath from "@/assets/icons/marker.png";
7
 import iconPath from "@/assets/icons/marker.png";
7
 import style from "./style.module.less";
8
 import style from "./style.module.less";
8
 
9
 

+ 5
- 0
src/index.html 查看文件

16
       charset="utf-8"
16
       charset="utf-8"
17
       src="https://map.qq.com/api/gljs?v=1.exp&key=HTPBZ-HHJA7-XD2XD-PRS37-H3HVJ-U5BAA&libraries=service"
17
       src="https://map.qq.com/api/gljs?v=1.exp&key=HTPBZ-HHJA7-XD2XD-PRS37-H3HVJ-U5BAA&libraries=service"
18
     ></script>
18
     ></script>
19
+    <!-- <script src="https://unpkg.com/vconsole@latest/dist/vconsole.min.js"></script>
20
+    <script>
21
+      // VConsole 默认会挂载到 `window.VConsole` 上
22
+      var vConsole = new window.VConsole();
23
+    </script> -->
19
 
24
 
20
     <title>civilized-miniapp</title>
25
     <title>civilized-miniapp</title>
21
     <script>
26
     <script>

+ 34
- 0
src/utils/map.js 查看文件

1
 import Taro from "@tarojs/taro";
1
 import Taro from "@tarojs/taro";
2
+import gcoord from 'gcoord';
2
 
3
 
3
 // 腾讯地图接口 - 个人开发者
4
 // 腾讯地图接口 - 个人开发者
4
 const QMAP_WEBSERVICE_KEY = 'HTPBZ-HHJA7-XD2XD-PRS37-H3HVJ-U5BAA';
5
 const QMAP_WEBSERVICE_KEY = 'HTPBZ-HHJA7-XD2XD-PRS37-H3HVJ-U5BAA';
27
     });
28
     });
28
   })
29
   })
29
 }
30
 }
31
+
32
+// 使用 HTML H5 API 获取当前定位信息
33
+// 返回 promise 对象
34
+// resolve 结果是 { lng, lat }
35
+export function getLocation() {
36
+  return new Promise((resolve, reject) => {
37
+    navigator.geolocation.getCurrentPosition(
38
+      (position) => {
39
+        console.log('----定位结果-->', JSON.stringify(position))
40
+        const { longitude, latitude } = position.coords;
41
+
42
+        const data = gcoord.transform(
43
+          [longitude, latitude],
44
+          gcoord.WGS84,
45
+          gcoord.GCJ02
46
+        );
47
+
48
+        const result = {
49
+          location: { lng: data[0], lat: data[1] }
50
+        }
51
+
52
+        resolve(result);
53
+      },
54
+      (err) => {
55
+        console.error('----定位失败-->', JSON.stringify(err))
56
+        reject(err);
57
+      },
58
+      {
59
+        enableHighAccuracy: true,
60
+      }
61
+    )
62
+  })
63
+}

+ 5
- 0
yarn.lock 查看文件

6978
   dependencies:
6978
   dependencies:
6979
     globule "~0.1.0"
6979
     globule "~0.1.0"
6980
 
6980
 
6981
+gcoord@^1.0.6:
6982
+  version "1.0.6"
6983
+  resolved "https://registry.npmmirror.com/gcoord/-/gcoord-1.0.6.tgz#bfb845b2014e9ef95012787517c75edaf04716ec"
6984
+  integrity sha512-Z+uyWrD2BTWmJOUvAdEAZQdQIVA5MFwUu7P5BfBdQEpLiVAsNw9mZF3/QbDJ4ZbfcJEnFKgHXOgUFXo5r/aVPg==
6985
+
6981
 generic-names@^4.0.0:
6986
 generic-names@^4.0.0:
6982
   version "4.0.0"
6987
   version "4.0.0"
6983
   resolved "https://registry.npmmirror.com/generic-names/-/generic-names-4.0.0.tgz"
6988
   resolved "https://registry.npmmirror.com/generic-names/-/generic-names-4.0.0.tgz"