|
@@ -83,26 +83,28 @@ public class TransfromDataTool {
|
|
|
return result;
|
|
|
}
|
|
|
AddressResult.ContentBean content = new AddressResult.ContentBean();
|
|
|
- content.setPname(jsonObject.getString("province"));
|
|
|
- content.setCityname(jsonObject.getString("district"));
|
|
|
- content.setAdname(jsonObject.getString("town"));
|
|
|
- content.setType(jsonObject.getString("type"));
|
|
|
- content.setAddress(jsonObject.getString("address"));
|
|
|
- content.setName(jsonObject.getString("address"));
|
|
|
- content.setSearchAddress(jsonObject.getString("searchAddress"));
|
|
|
- content.setScore(jsonObject.getString("总分"));
|
|
|
- if (jsonObject.containsKey("location") && jsonObject.getJSONObject("location").containsKey("lat") && jsonObject.getJSONObject("location").containsKey("lng")) {
|
|
|
- double[] points = CoordTransform2.getInstance().shcj_to_wgs84(
|
|
|
- Double.parseDouble(jsonObject.getJSONObject("location").getString("lat")), Double.parseDouble(jsonObject.getJSONObject("location").getString("lng")));
|
|
|
- content.setLocation(points[0] + "," + points[1]);
|
|
|
- content.setLat(points[0]);
|
|
|
- content.setLon(points[1]);
|
|
|
- }
|
|
|
- if (result.getData() == null) {
|
|
|
- result.setData(new ArrayList<>());
|
|
|
+ if (jsonObject.containsKey("总分") && jsonObject.get("总分") != null) {
|
|
|
+ content.setPname(jsonObject.getString("province"));
|
|
|
+ content.setCityname(jsonObject.getString("district"));
|
|
|
+ content.setAdname(jsonObject.getString("town"));
|
|
|
+ content.setType(jsonObject.getString("type"));
|
|
|
+ content.setAddress(jsonObject.getString("address"));
|
|
|
+ content.setName(jsonObject.getString("address"));
|
|
|
+ content.setSearchAddress(jsonObject.getString("searchAddress"));
|
|
|
+ content.setScore(jsonObject.getString("总分"));
|
|
|
+ if (jsonObject.containsKey("location") && jsonObject.getJSONObject("location").containsKey("lat") && jsonObject.getJSONObject("location").containsKey("lng")) {
|
|
|
+ double[] points = CoordTransform2.getInstance().shcj_to_wgs84(
|
|
|
+ Double.parseDouble(jsonObject.getJSONObject("location").getString("lat")), Double.parseDouble(jsonObject.getJSONObject("location").getString("lng")));
|
|
|
+ content.setLocation(points[0] + "," + points[1]);
|
|
|
+ content.setLat(points[0]);
|
|
|
+ content.setLon(points[1]);
|
|
|
+ }
|
|
|
+ if (result.getData() == null) {
|
|
|
+ result.setData(new ArrayList<>());
|
|
|
+ }
|
|
|
+ result.getData().add(content);
|
|
|
+ result.setCode(AddressResultEnum.WDJA_SUCCESS);
|
|
|
}
|
|
|
- result.getData().add(content);
|
|
|
- result.setCode(AddressResultEnum.WDJA_SUCCESS);
|
|
|
return result;
|
|
|
}
|
|
|
|
|
@@ -113,51 +115,53 @@ public class TransfromDataTool {
|
|
|
result.setCode(AddressResultEnum.RESULT_NULL);
|
|
|
return result;
|
|
|
}
|
|
|
- com.skyversation.poiaddr.util.AddressTools.getInstance().findBestMatch(searchAddress, array, "address");
|
|
|
JSONObject jsonObject = com.skyversation.poiaddr.util.AddressTools.getInstance().findBestMatch(searchAddress, array, "address");
|
|
|
- AddressResult.ContentBean content = new AddressResult.ContentBean();
|
|
|
- content.setType(jsonObject.getString("type_name"));
|
|
|
- List<String> addressList = new ArrayList<>();
|
|
|
- content.setAddress(jsonObject.getString("address"));
|
|
|
- if (!jsonObject.getString("address").isEmpty()) {
|
|
|
- addressList.add(jsonObject.getString("address"));
|
|
|
- }
|
|
|
- if (!jsonObject.getString("std_address").isEmpty()) {
|
|
|
- addressList.add(jsonObject.getString("std_address"));
|
|
|
- }
|
|
|
- content.setName(jsonObject.getString("name"));
|
|
|
- double[] points = new double[]{jsonObject.getJSONObject("location").getDouble("lng"),
|
|
|
- jsonObject.getJSONObject("location").getDouble("lat")};
|
|
|
- content.setLocation(points[0] + "," + points[1]);
|
|
|
- content.setLon(points[0]);
|
|
|
- content.setLat(points[1]);
|
|
|
- if (jsonObject.containsKey("ext_data")) {
|
|
|
- JSONObject extData = jsonObject.getJSONObject("ext_data");
|
|
|
- if (extData.containsKey("address") && !extData.getString("address").isEmpty()) {
|
|
|
- addressList.add(extData.getString("address"));
|
|
|
+ if (jsonObject.containsKey("总分") && jsonObject.get("总分") != null && !jsonObject.getString("总分").isEmpty()) {
|
|
|
+ AddressResult.ContentBean content = new AddressResult.ContentBean();
|
|
|
+ content.setScore(jsonObject.getString("总分"));
|
|
|
+ content.setSearchAddress(jsonObject.getString("searchAddress"));
|
|
|
+ content.setType(jsonObject.getString("type_name"));
|
|
|
+ List<String> addressList = new ArrayList<>();
|
|
|
+ content.setAddress(jsonObject.getString("address"));
|
|
|
+ if (!jsonObject.getString("address").isEmpty()) {
|
|
|
+ addressList.add(jsonObject.getString("address"));
|
|
|
}
|
|
|
- if (extData.containsKey("source_address") && !extData.getString("source_address").isEmpty()) {
|
|
|
- addressList.add(extData.getString("source_address"));
|
|
|
+ if (!jsonObject.getString("std_address").isEmpty()) {
|
|
|
+ addressList.add(jsonObject.getString("std_address"));
|
|
|
}
|
|
|
+ content.setName(jsonObject.getString("name"));
|
|
|
+ double[] points = new double[]{jsonObject.getJSONObject("location").getDouble("lng"),
|
|
|
+ jsonObject.getJSONObject("location").getDouble("lat")};
|
|
|
+ content.setLocation(points[0] + "," + points[1]);
|
|
|
+ content.setLon(points[1]);
|
|
|
+ content.setLat(points[0]);
|
|
|
+ if (jsonObject.containsKey("ext_data")) {
|
|
|
+ JSONObject extData = jsonObject.getJSONObject("ext_data");
|
|
|
+ if (extData.containsKey("address") && !extData.getString("address").isEmpty()) {
|
|
|
+ addressList.add(extData.getString("address"));
|
|
|
+ }
|
|
|
+ if (extData.containsKey("source_address") && !extData.getString("source_address").isEmpty()) {
|
|
|
+ addressList.add(extData.getString("source_address"));
|
|
|
+ }
|
|
|
|
|
|
- if (extData.containsKey("region_jw") && !extData.getString("region_jw").isEmpty()) {
|
|
|
- JSONObject cjJson = new JSONObject();
|
|
|
- cjJson.put("所属街道", extData.getString("region_jd"));
|
|
|
- cjJson.put("所属居委", extData.getString("region_jw"));
|
|
|
- content.setCjJson(cjJson);
|
|
|
+ if (extData.containsKey("region_jw") && !extData.getString("region_jw").isEmpty()) {
|
|
|
+ JSONObject cjJson = new JSONObject();
|
|
|
+ cjJson.put("所属街道", extData.getString("region_jd"));
|
|
|
+ cjJson.put("所属居委", extData.getString("region_jw"));
|
|
|
+ content.setCjJson(cjJson);
|
|
|
+ }
|
|
|
}
|
|
|
-
|
|
|
- }
|
|
|
- for (String item : addressList) {
|
|
|
- if (item.contains("上海市") && item.contains(Constant.getArea() + "区") && item.length() > content.getAddress().length()) {
|
|
|
- content.setAddress(item);
|
|
|
+ for (String item : addressList) {
|
|
|
+ if (item.contains("上海市") && item.contains(Constant.getArea() + "区") && item.length() > content.getAddress().length()) {
|
|
|
+ content.setAddress(item);
|
|
|
+ }
|
|
|
}
|
|
|
+ if (result.getData() == null) {
|
|
|
+ result.setData(new ArrayList<>());
|
|
|
+ }
|
|
|
+ result.getData().add(content);
|
|
|
+ result.setCode(AddressResultEnum.SZX_SUCCESS);
|
|
|
}
|
|
|
- if (result.getData() == null) {
|
|
|
- result.setData(new ArrayList<>());
|
|
|
- }
|
|
|
- result.getData().add(content);
|
|
|
- result.setCode(AddressResultEnum.SZX_SUCCESS);
|
|
|
return result;
|
|
|
}
|
|
|
|