diff --git a/hai-cweb/src/main/java/com/cweb/controller/CommonController.java b/hai-cweb/src/main/java/com/cweb/controller/CommonController.java index c81e4c34..9f7fa937 100644 --- a/hai-cweb/src/main/java/com/cweb/controller/CommonController.java +++ b/hai-cweb/src/main/java/com/cweb/controller/CommonController.java @@ -287,8 +287,17 @@ public class CommonController { ) { try { + + JSONObject jsonObjectR = commonService.findByLatAndLng(lng , lat); + + if (!jsonObjectR.getString("status").equals("0")) { + log.error("findByLatAndLng error!", "定位错误,请重新定位" ); + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "定位错误,请重新定位"); + } + JSONObject object = commonService.findByLatAndLng(lng , lat).getJSONObject("result").getJSONObject("addressComponent"); + ApiCity apiCity = commonService.findCityByName(object.getString("city")); if (apiCity == null) { diff --git a/hai-service/src/main/java/com/hai/service/impl/CommonServiceImpl.java b/hai-service/src/main/java/com/hai/service/impl/CommonServiceImpl.java index 6ff7a0ed..ad6bbe8a 100644 --- a/hai-service/src/main/java/com/hai/service/impl/CommonServiceImpl.java +++ b/hai-service/src/main/java/com/hai/service/impl/CommonServiceImpl.java @@ -534,18 +534,20 @@ public class CommonServiceImpl implements CommonService { @Override public JSONObject findByLatAndLng(String lng, String lat) throws Exception { - Map map = new HashMap<>();//参数 - map.put("ak", "SfrwGH7INvjPq7BwCrYrioBQZm9XXxrR");//申请百度开放平台KEY(ak) - map.put("output", "json");// 输出Json数据 - map.put("extensions_town", "true");// 行政区划返回乡镇级数据(town),仅国内召回乡镇数据 - map.put("coordtype", "wgs84ll"); // GPS 经纬度类型 - map.put("location", lat+","+lng+"");//百度经纬度 - - String url = "http://api.map.baidu.com/reverse_geocoding/v3/"; - - System.out.println("请求经纬度========" + map); - - return HttpsUtils.doGet(url , map); + //参数 + Map map = new HashMap<>(); + //申请百度开放平台KEY(ak) + map.put("ak", "SfrwGH7INvjPq7BwCrYrioBQZm9XXxrR"); + // 输出Json数据 + map.put("output", "json"); + // 行政区划返回乡镇级数据(town),仅国内召回乡镇数据 + map.put("extensions_town", "true"); + // GPS 经纬度类型 + map.put("coordtype", "wgs84ll"); + //百度经纬度 + map.put("location", lat+","+lng+""); + + return HttpsUtils.doGet("http://api.map.baidu.com/reverse_geocoding/v3/" , map); }