浏览代码

修复地图经纬度转地址报错问题

Hwf 4 天之前
父节点
当前提交
9f27d888fc

+ 5 - 0
index.html

@@ -11,6 +11,11 @@
     <script src="/static/h5player.min.js"></script>
     <!-- script src="/static/szca_crypto.js"></script -->
     <!-- script src="/static/szca_base64.js"></script -->
+      <script>
+          window._AMapSecurityConfig = {
+              securityJsCode: '4868bc1b8fac7d9e54e7279ed556879a'
+          };
+      </script>
     <title>应急工作台移动端</title>
   </head>
   <body>

+ 7 - 8
src/components/PositionSelect/index.vue

@@ -175,7 +175,7 @@ function handlePanTo(index) {
 const updateForm = (position) => {
   form.longitude = position[0];
   form.latitude = position[1];
-  if (position === [110.925175, 21.678955]) {
+  if (position[0] == 110.925175 && position[1] == 21.678955) {
     form.address = '广东省茂名市茂南区官渡街道茂名市应急管理局'
   } else {
     geocoder.getAddress(position, (status, result) => {
@@ -186,9 +186,6 @@ const updateForm = (position) => {
   }
 };
 const initMap = async () => {
-  window._AMapSecurityConfig = {
-    securityJsCode: '4868bc1b8fac7d9e54e7279ed556879a'
-  };
   const AMap = await AMapLoader.load({
     key: '9c5041381e5e824f9ee324d8f7a40150', // 申请好的Web端开发者Key,首次调用 load 时必填
     version: '2.0', // 指定要加载的 JSAPI 的版本,缺省时默认为 1.4.15
@@ -224,10 +221,12 @@ const initMap = async () => {
     zoom: 15
   });
   amap = AMap;
-  geocoder = new AMap.Geocoder({
-    // city 指定进行编码查询的城市,支持传入城市名、adcode 和 citycode
-    city: '010'
-  });
+  AMap.plugin('AMap.Geocoder', function() {
+    geocoder = new AMap.Geocoder({
+      // city 指定进行编码查询的城市,支持传入城市名、adcode 和 citycode
+      city: '010'
+    });
+  })
   // 创建右键菜单
   ContextMenu();
   map.on('rightclick', handleRightclick);

+ 0 - 3
src/views/event/PositionSelect.vue

@@ -201,9 +201,6 @@ const updateForm = (position) => {
 };
 const initMap = async () => {
   let position = [110.925175, 21.678955];
-  window._AMapSecurityConfig = {
-    securityJsCode: '4868bc1b8fac7d9e54e7279ed556879a'
-  };
   const AMap = await AMapLoader.load({
     key: '9c5041381e5e824f9ee324d8f7a40150', // 申请好的Web端开发者Key,首次调用 load 时必填
     version: '2.0', // 指定要加载的 JSAPI 的版本,缺省时默认为 1.4.15

+ 0 - 3
src/views/mobileControl/PositionSelect.vue

@@ -320,9 +320,6 @@ const initMap = async () => {
   if (!!props.id) {
     position = [form.value.longitude, form.value.latitude];
   }
-  window._AMapSecurityConfig = {
-    securityJsCode: "4868bc1b8fac7d9e54e7279ed556879a"
-  };
   const AMap = await AMapLoader.load({
     key: "9c5041381e5e824f9ee324d8f7a40150", // 申请好的Web端开发者Key,首次调用 load 时必填
     version: "2.0", // 指定要加载的 JSAPI 的版本,缺省时默认为 1.4.15