|
@@ -1,13 +1,12 @@
|
|
package com.bizmatics.mhfire.service.util;
|
|
package com.bizmatics.mhfire.service.util;
|
|
|
|
|
|
import com.bizmatics.common.core.util.HttpUtils;
|
|
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.beans.factory.annotation.Value;
|
|
import org.springframework.stereotype.Component;
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
import java.io.IOException;
|
|
import java.io.IOException;
|
|
-import java.util.Map;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
* @author yq
|
|
* @author yq
|
|
@@ -45,8 +44,18 @@ public class GouldUtil {
|
|
// 返回输入地址address的经纬度信息, 格式是 经度,纬度
|
|
// 返回输入地址address的经纬度信息, 格式是 经度,纬度
|
|
String queryUrl = "http://restapi.amap.com/v3/geocode/geo?key="+gouldKey+"&address=" + address;
|
|
String queryUrl = "http://restapi.amap.com/v3/geocode/geo?key="+gouldKey+"&address=" + address;
|
|
String queryResult = getResponse(queryUrl); // 高德接品返回的是JSON格式的字符串
|
|
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;
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|