李志伟 3 年之前
父節點
當前提交
92d453abc6
共有 1 個檔案被更改,包括 9 行新增8 行删除
  1. 9
    8
      src/pages/index/index.jsx

+ 9
- 8
src/pages/index/index.jsx 查看文件

36
       Taro.redirectTo({ url: `/pages/index/index?tab=${val}` });
36
       Taro.redirectTo({ url: `/pages/index/index?tab=${val}` });
37
     }
37
     }
38
   };
38
   };
39
+  const getAmap = (loc) => {
40
+    setAmap({ params: 'location=' + loc, path: '/v3/geocode/regeo' }).then(res2 => {
41
+      //josn对象取值
42
+      setAddress(JSON.parse(res2)['regeocode'].formatted_address)
43
+    })
44
+  }
45
+
39
   useEffect(() => {
46
   useEffect(() => {
40
     if (!location) {
47
     if (!location) {
41
       Taro.getLocation({
48
       Taro.getLocation({
42
         type: 'gcj02',
49
         type: 'gcj02',
43
         success: function (res) {
50
         success: function (res) {
44
           setLocation(res.longitude + ',' + res.latitude)
51
           setLocation(res.longitude + ',' + res.latitude)
45
-          setAmap({ params: 'location=' + res.longitude + ',' + res.latitude, path: '/v3/geocode/regeo' }).then(res2 => {
46
-            //josn对象取值
47
-            setAddress(JSON.parse(res2)['regeocode'].formatted_address)
48
-          })
52
+          getAmap(res.longitude + ',' + res.latitude)
49
         }
53
         }
50
       })
54
       })
51
     } else {
55
     } else {
52
-      setAmap({ params: 'location=' + location, path: '/v3/geocode/regeo' }).then(res2 => {
53
-        //josn对象取值
54
-        setAddress(JSON.parse(res2)['regeocode'].formatted_address)
55
-      })
56
+      getAmap(location)
56
     }
57
     }
57
   }, [])
58
   }, [])
58
   return (
59
   return (