| | |
| | | if (count == null) { |
| | | count = 10; |
| | | } |
| | | |
| | | // 构建天地图普通搜索API URL |
| | | //{"keyWord":"广州天河棠下","level":12,"mapBound":"116.02524,39.83833,116.65592,39.99185","queryType":1,"start":0,"count":10} |
| | | // 构建天地图普通搜索API URL http://api.tianditu.gov.cn/v2/search |
| | | String url = "http://api.tianditu.gov.cn/v2/search"; |
| | | StringBuilder paramsBuilder = new StringBuilder(); |
| | | paramsBuilder.append("postStr={\"keyWord\":\"").append(keyWord).append("\""); |
| | | // 硬编码中国地图范围 |
| | | paramsBuilder.append(",\"mapBound\":\"").append("73.66,3.86,135.05,53.55").append("\""); |
| | | // 默认级别为18 |
| | | paramsBuilder.append(",\"level\":\"").append("18").append("\""); |
| | | paramsBuilder.append(",\"level\":\"").append("12").append("\""); |
| | | // 默认查询类型为普通搜索 |
| | | paramsBuilder.append(",\"queryType\":\"").append("1").append("\""); |
| | | // 默认起始位置为0 |
| | |
| | | paramsBuilder.append(",\"count\":\"").append(count).append("\""); |
| | | |
| | | // 添加可选参数 |
| | | if (region != null && !region.trim().isEmpty()) { |
| | | paramsBuilder.append(",\"specify\":\"").append(region).append("\""); |
| | | } |
| | | if (city != null && !city.trim().isEmpty()) { |
| | | paramsBuilder.append(",\"dataTypes\":\"").append(city).append("\""); |
| | | } |
| | | // if (region != null && !region.trim().isEmpty()) { |
| | | // paramsBuilder.append(",\"specify\":\"").append(region).append("\""); |
| | | // } |
| | | // if (city != null && !city.trim().isEmpty()) { |
| | | // paramsBuilder.append(",\"dataTypes\":\"").append(city).append("\""); |
| | | // } |
| | | |
| | | paramsBuilder.append("}"); |
| | | paramsBuilder.append("&type=query"); |
| | |
| | | } |
| | | |
| | | JSONArray results = jsonResponse.getJSONArray("pois"); |
| | | |
| | | if(results==null|| results.isEmpty()){ |
| | | return AjaxResult.error("未找到匹配的地址"); |
| | | } |
| | | |
| | | // 构建返回结果 |
| | | List<Map<String, Object>> suggestions = new ArrayList<>(); |