Pārlūkot izejas kodu

精度维度转换

yq 3 gadi atpakaļ
vecāks
revīzija
63cab7c870

+ 14 - 5
mhfire-service/src/main/java/com/bizmatics/mhfire/service/util/GouldUtil.java

@@ -1,13 +1,12 @@
 package com.bizmatics.mhfire.service.util;
 
 import com.bizmatics.common.core.util.HttpUtils;
-import com.bizmatics.common.spring.util.JsonUtils;
-import com.fasterxml.jackson.core.type.TypeReference;
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Component;
 
 import java.io.IOException;
-import java.util.Map;
 
 /**
  * @author yq
@@ -45,8 +44,18 @@ public class GouldUtil {
         // 返回输入地址address的经纬度信息, 格式是 经度,纬度
         String queryUrl = "http://restapi.amap.com/v3/geocode/geo?key="+gouldKey+"&address=" + address;
         String queryResult = getResponse(queryUrl); // 高德接品返回的是JSON格式的字符串
-        Map<String, Object> result = JsonUtils.fromJson(queryResult, new TypeReference<Map<String, Object>>() {});
-        return result.get("location").toString();
+        String result = "";
+        try {
+            JsonNode arrNode = new ObjectMapper().readTree(queryResult).get("geocodes");
+            if (arrNode.isArray()) {
+                for (JsonNode objNode : arrNode) {
+                    result = objNode.get("location").toString();
+                }
+            }
+        }catch (Exception e){
+            e.getMessage();
+        }
+        return result;
     }
 
     /**