求某个医院的近似经纬度

x33g5p2x  于2022-06-06 转载在 其他  
字(12.6k)|赞(0)|评价(0)|浏览(211)

一 代码

1 返回结果封装

Biz_ext

  1. package hospital;
  2. import java.util.List;
  3. public class Biz_ext {
  4. private List<String> cost;
  5. private List<String> rating;
  6. public void setCost(List<String> cost) {
  7. this.cost = cost;
  8. }
  9. public List<String> getCost() {
  10. return cost;
  11. }
  12. public void setRating(List<String> rating) {
  13. this.rating = rating;
  14. }
  15. public List<String> getRating() {
  16. return rating;
  17. }
  18. }

Children

  1. package hospital;
  2. public class Children {
  3. private String typecode;
  4. private String address;
  5. private String distance;
  6. private String subtype;
  7. private String sname;
  8. private String name;
  9. private String location;
  10. private String id;
  11. public void setTypecode(String typecode) {
  12. this.typecode = typecode;
  13. }
  14. public String getTypecode() {
  15. return typecode;
  16. }
  17. public void setAddress(String address) {
  18. this.address = address;
  19. }
  20. public String getAddress() {
  21. return address;
  22. }
  23. public void setDistance(String distance) {
  24. this.distance = distance;
  25. }
  26. public String getDistance() {
  27. return distance;
  28. }
  29. public void setSubtype(String subtype) {
  30. this.subtype = subtype;
  31. }
  32. public String getSubtype() {
  33. return subtype;
  34. }
  35. public void setSname(String sname) {
  36. this.sname = sname;
  37. }
  38. public String getSname() {
  39. return sname;
  40. }
  41. public void setName(String name) {
  42. this.name = name;
  43. }
  44. public String getName() {
  45. return name;
  46. }
  47. public void setLocation(String location) {
  48. this.location = location;
  49. }
  50. public String getLocation() {
  51. return location;
  52. }
  53. public void setId(String id) {
  54. this.id = id;
  55. }
  56. public String getId() {
  57. return id;
  58. }
  59. }

HospitalResponse

  1. package hospital;
  2. import java.util.List;
  3. public class HospitalResponse {
  4. private Suggestion suggestion;
  5. private String count;
  6. private String infocode;
  7. private List<Pois> pois;
  8. private String status;
  9. private String info;
  10. public void setSuggestion(Suggestion suggestion) {
  11. this.suggestion = suggestion;
  12. }
  13. public Suggestion getSuggestion() {
  14. return suggestion;
  15. }
  16. public void setCount(String count) {
  17. this.count = count;
  18. }
  19. public String getCount() {
  20. return count;
  21. }
  22. public void setInfocode(String infocode) {
  23. this.infocode = infocode;
  24. }
  25. public String getInfocode() {
  26. return infocode;
  27. }
  28. public void setPois(List<Pois> pois) {
  29. this.pois = pois;
  30. }
  31. public List<Pois> getPois() {
  32. return pois;
  33. }
  34. public void setStatus(String status) {
  35. this.status = status;
  36. }
  37. public String getStatus() {
  38. return status;
  39. }
  40. public void setInfo(String info) {
  41. this.info = info;
  42. }
  43. public String getInfo() {
  44. return info;
  45. }
  46. }

Indoor_data

  1. package hospital;
  2. import java.util.List;
  3. public class Indoor_data {
  4. private List<String> cmsid;
  5. private List<String> truefloor;
  6. private List<String> cpid;
  7. private List<String> floor;
  8. public void setCmsid(List<String> cmsid) {
  9. this.cmsid = cmsid;
  10. }
  11. public List<String> getCmsid() {
  12. return cmsid;
  13. }
  14. public void setTruefloor(List<String> truefloor) {
  15. this.truefloor = truefloor;
  16. }
  17. public List<String> getTruefloor() {
  18. return truefloor;
  19. }
  20. public void setCpid(List<String> cpid) {
  21. this.cpid = cpid;
  22. }
  23. public List<String> getCpid() {
  24. return cpid;
  25. }
  26. public void setFloor(List<String> floor) {
  27. this.floor = floor;
  28. }
  29. public List<String> getFloor() {
  30. return floor;
  31. }
  32. }

Photos

  1. package hospital;
  2. import java.util.List;
  3. public class Photos {
  4. private List<String> title;
  5. private String url;
  6. public void setTitle(List<String> title) {
  7. this.title = title;
  8. }
  9. public List<String> getTitle() {
  10. return title;
  11. }
  12. public void setUrl(String url) {
  13. this.url = url;
  14. }
  15. public String getUrl() {
  16. return url;
  17. }
  18. }

Pois

  1. package hospital;
  2. import java.util.Date;
  3. import java.util.List;
  4. public class Pois {
  5. private List<String> parent;
  6. private List<String> distance;
  7. private String pcode;
  8. private List<String> importance;
  9. private Biz_ext biz_ext;
  10. private String recommend;
  11. private String type;
  12. private List<Photos> photos;
  13. private String discount_num;
  14. private String gridcode;
  15. private String typecode;
  16. private String shopinfo;
  17. private List<String> poiweight;
  18. private String citycode;
  19. private String adname;
  20. private List<Children> children;
  21. private String alias;
  22. private String tel;
  23. private String id;
  24. private String tag;
  25. private List<String> event;
  26. private String entr_location;
  27. private String indoor_map;
  28. private List<String> email;
  29. private Date timestamp;
  30. private String website;
  31. private String address;
  32. private String adcode;
  33. private String pname;
  34. private List<String> biz_type;
  35. private String cityname;
  36. private List<String> postcode;
  37. private String match;
  38. private String business_area;
  39. private Indoor_data Indoor_data;
  40. private List<String> childtype;
  41. private List<String> exit_location;
  42. private String name;
  43. private String location;
  44. private List<String> shopid;
  45. private String navi_poiid;
  46. private String groupbuy_num;
  47. public void setParent(List<String> parent) {
  48. this.parent = parent;
  49. }
  50. public List<String> getParent() {
  51. return parent;
  52. }
  53. public void setDistance(List<String> distance) {
  54. this.distance = distance;
  55. }
  56. public List<String> getDistance() {
  57. return distance;
  58. }
  59. public void setPcode(String pcode) {
  60. this.pcode = pcode;
  61. }
  62. public String getPcode() {
  63. return pcode;
  64. }
  65. public void setImportance(List<String> importance) {
  66. this.importance = importance;
  67. }
  68. public List<String> getImportance() {
  69. return importance;
  70. }
  71. public void setBiz_ext(Biz_ext biz_ext) {
  72. this.biz_ext = biz_ext;
  73. }
  74. public Biz_ext getBiz_ext() {
  75. return biz_ext;
  76. }
  77. public void setRecommend(String recommend) {
  78. this.recommend = recommend;
  79. }
  80. public String getRecommend() {
  81. return recommend;
  82. }
  83. public void setType(String type) {
  84. this.type = type;
  85. }
  86. public String getType() {
  87. return type;
  88. }
  89. public void setPhotos(List<Photos> photos) {
  90. this.photos = photos;
  91. }
  92. public List<Photos> getPhotos() {
  93. return photos;
  94. }
  95. public void setDiscount_num(String discount_num) {
  96. this.discount_num = discount_num;
  97. }
  98. public String getDiscount_num() {
  99. return discount_num;
  100. }
  101. public void setGridcode(String gridcode) {
  102. this.gridcode = gridcode;
  103. }
  104. public String getGridcode() {
  105. return gridcode;
  106. }
  107. public void setTypecode(String typecode) {
  108. this.typecode = typecode;
  109. }
  110. public String getTypecode() {
  111. return typecode;
  112. }
  113. public void setShopinfo(String shopinfo) {
  114. this.shopinfo = shopinfo;
  115. }
  116. public String getShopinfo() {
  117. return shopinfo;
  118. }
  119. public void setPoiweight(List<String> poiweight) {
  120. this.poiweight = poiweight;
  121. }
  122. public List<String> getPoiweight() {
  123. return poiweight;
  124. }
  125. public void setCitycode(String citycode) {
  126. this.citycode = citycode;
  127. }
  128. public String getCitycode() {
  129. return citycode;
  130. }
  131. public void setAdname(String adname) {
  132. this.adname = adname;
  133. }
  134. public String getAdname() {
  135. return adname;
  136. }
  137. public void setChildren(List<Children> children) {
  138. this.children = children;
  139. }
  140. public List<Children> getChildren() {
  141. return children;
  142. }
  143. public void setAlias(String alias) {
  144. this.alias = alias;
  145. }
  146. public String getAlias() {
  147. return alias;
  148. }
  149. public void setTel(String tel) {
  150. this.tel = tel;
  151. }
  152. public String getTel() {
  153. return tel;
  154. }
  155. public void setId(String id) {
  156. this.id = id;
  157. }
  158. public String getId() {
  159. return id;
  160. }
  161. public void setTag(String tag) {
  162. this.tag = tag;
  163. }
  164. public String getTag() {
  165. return tag;
  166. }
  167. public void setEvent(List<String> event) {
  168. this.event = event;
  169. }
  170. public List<String> getEvent() {
  171. return event;
  172. }
  173. public void setEntr_location(String entr_location) {
  174. this.entr_location = entr_location;
  175. }
  176. public String getEntr_location() {
  177. return entr_location;
  178. }
  179. public void setIndoor_map(String indoor_map) {
  180. this.indoor_map = indoor_map;
  181. }
  182. public String getIndoor_map() {
  183. return indoor_map;
  184. }
  185. public void setEmail(List<String> email) {
  186. this.email = email;
  187. }
  188. public List<String> getEmail() {
  189. return email;
  190. }
  191. public void setTimestamp(Date timestamp) {
  192. this.timestamp = timestamp;
  193. }
  194. public Date getTimestamp() {
  195. return timestamp;
  196. }
  197. public void setWebsite(String website) {
  198. this.website = website;
  199. }
  200. public String getWebsite() {
  201. return website;
  202. }
  203. public void setAddress(String address) {
  204. this.address = address;
  205. }
  206. public String getAddress() {
  207. return address;
  208. }
  209. public void setAdcode(String adcode) {
  210. this.adcode = adcode;
  211. }
  212. public String getAdcode() {
  213. return adcode;
  214. }
  215. public void setPname(String pname) {
  216. this.pname = pname;
  217. }
  218. public String getPname() {
  219. return pname;
  220. }
  221. public void setBiz_type(List<String> biz_type) {
  222. this.biz_type = biz_type;
  223. }
  224. public List<String> getBiz_type() {
  225. return biz_type;
  226. }
  227. public void setCityname(String cityname) {
  228. this.cityname = cityname;
  229. }
  230. public String getCityname() {
  231. return cityname;
  232. }
  233. public void setPostcode(List<String> postcode) {
  234. this.postcode = postcode;
  235. }
  236. public List<String> getPostcode() {
  237. return postcode;
  238. }
  239. public void setMatch(String match) {
  240. this.match = match;
  241. }
  242. public String getMatch() {
  243. return match;
  244. }
  245. public void setBusiness_area(String business_area) {
  246. this.business_area = business_area;
  247. }
  248. public String getBusiness_area() {
  249. return business_area;
  250. }
  251. public void setIndoor_data(Indoor_data indoor_data) {
  252. this.Indoor_data = indoor_data;
  253. }
  254. public Indoor_data getIndoor_data() {
  255. return Indoor_data;
  256. }
  257. public void setChildtype(List<String> childtype) {
  258. this.childtype = childtype;
  259. }
  260. public List<String> getChildtype() {
  261. return childtype;
  262. }
  263. public void setExit_location(List<String> exit_location) {
  264. this.exit_location = exit_location;
  265. }
  266. public List<String> getExit_location() {
  267. return exit_location;
  268. }
  269. public void setName(String name) {
  270. this.name = name;
  271. }
  272. public String getName() {
  273. return name;
  274. }
  275. public void setLocation(String location) {
  276. this.location = location;
  277. }
  278. public String getLocation() {
  279. return location;
  280. }
  281. public void setShopid(List<String> shopid) {
  282. this.shopid = shopid;
  283. }
  284. public List<String> getShopid() {
  285. return shopid;
  286. }
  287. public void setNavi_poiid(String navi_poiid) {
  288. this.navi_poiid = navi_poiid;
  289. }
  290. public String getNavi_poiid() {
  291. return navi_poiid;
  292. }
  293. public void setGroupbuy_num(String groupbuy_num) {
  294. this.groupbuy_num = groupbuy_num;
  295. }
  296. public String getGroupbuy_num() {
  297. return groupbuy_num;
  298. }
  299. }

Suggestion

  1. package hospital;
  2. import java.util.List;
  3. public class Suggestion {
  4. private List<String> keywords;
  5. private List<String> cities;
  6. public void setKeywords(List<String> keywords) {
  7. this.keywords = keywords;
  8. }
  9. public List<String> getKeywords() {
  10. return keywords;
  11. }
  12. public void setCities(List<String> cities) {
  13. this.cities = cities;
  14. }
  15. public List<String> getCities() {
  16. return cities;
  17. }
  18. }

2 Http 工具类

  1. package hospital;
  2. import org.apache.commons.logging.Log;
  3. import org.apache.commons.logging.LogFactory;
  4. import org.apache.http.HttpEntity;
  5. import org.apache.http.HttpResponse;
  6. import org.apache.http.ParseException;
  7. import org.apache.http.client.ClientProtocolException;
  8. import org.apache.http.client.HttpClient;
  9. import org.apache.http.client.methods.HttpGet;
  10. import org.apache.http.impl.client.DefaultHttpClient;
  11. import org.apache.http.util.EntityUtils;
  12. import java.io.IOException;
  13. /**
  14. * @className: HttpClientUtils
  15. * @description: 本工具采用的是最新的 HttpComponents-Client-4.2.1 ,封装了一些采用 HttpClient 发送 HTTP 请求的方法
  16. * @date: 2021/2/10
  17. * @author: cakin
  18. */
  19. public class HttpClientUtils {
  20. private static Log logger = LogFactory.getLog(hospital.HttpClientUtils.class);
  21. private HttpClientUtils() {
  22. }
  23. /**
  24. * 发送HTTP_GET请求
  25. *
  26. * @param reqURL 请求地址(含参数)
  27. * @param decodeCharset 解码字符集,解析响应数据时用之,其为null时默认采用UTF-8解码
  28. * @return 远程主机响应正文
  29. */
  30. public static String sendGetRequest(String reqURL, String decodeCharset) {
  31. long responseLength = 0; //响应长度
  32. String responseContent = null; //响应内容
  33. HttpClient httpClient = new DefaultHttpClient(); //创建默认的httpClient实例
  34. HttpGet httpGet = new HttpGet(reqURL); //创建org.apache.http.client.methods.HttpGet
  35. try {
  36. HttpResponse response = httpClient.execute(httpGet); //执行GET请求
  37. HttpEntity entity = response.getEntity(); //获取响应实体
  38. if (null != entity) {
  39. responseLength = entity.getContentLength();
  40. responseContent = EntityUtils.toString(entity, decodeCharset == null ? "UTF-8" : decodeCharset);
  41. EntityUtils.consume(entity); //Consume response content
  42. }
  43. System.out.println("请求地址: " + httpGet.getURI());
  44. System.out.println("响应状态: " + response.getStatusLine());
  45. System.out.println("响应长度: " + responseLength);
  46. System.out.println("响应内容: " + responseContent);
  47. } catch (ClientProtocolException e) {
  48. logger.debug("该异常通常是协议错误导致,比如构造HttpGet对象时传入的协议不对(将'http'写成'htp')或者服务器端返回的内容不符合HTTP协议要求等,堆栈信息如下", e);
  49. } catch (ParseException e) {
  50. logger.debug(e.getMessage(), e);
  51. } catch (IOException e) {
  52. logger.debug("该异常通常是网络原因引起的,如HTTP服务器未启动等,堆栈信息如下", e);
  53. } finally {
  54. httpClient.getConnectionManager().shutdown(); //关闭连接,释放资源
  55. }
  56. return responseContent;
  57. }
  58. }

3 测试类

  1. package hospital;
  2. import com.alibaba.fastjson.JSON;
  3. import com.alibaba.fastjson.JSONArray;
  4. import com.alibaba.fastjson.JSONObject;
  5. import org.apache.commons.lang3.StringUtils;
  6. /**
  7. * @className: Test
  8. * @description: 求某个医院的近似经纬度,参考 https://lbs.amap.com/api/webservice/guide/api/search
  9. * @date: 2022/6/2
  10. * @author: cakin
  11. */
  12. public class Test {
  13. public static void main(String[] args) {
  14. String keyWord = "西京医院";
  15. String reqURL = "https://restapi.amap.com/v3/place/text?key=019283b6XXXXe7499f4ec877f5ab&keywords=" + keyWord + "&types=&city=&children=1&offset=1000&page=1&extensions=all";
  16. String result = HttpClientUtils.sendGetRequest(reqURL, null);
  17. JSONObject jsonObject = JSON.parseObject(result);
  18. JSONArray arrayObj = jsonObject.getJSONArray("pois");
  19. String keyLocation = "";
  20. for (int i = 0; i < arrayObj.size(); i++) {
  21. JSONObject poisObject = arrayObj.getJSONObject(i);
  22. String location = poisObject.getString("location");
  23. String name = poisObject.getString("name");
  24. String alias = poisObject.getString("alias");
  25. System.out.println(name);
  26. System.out.println(alias);
  27. System.out.println(location);
  28. System.out.println("--------------");
  29. if (keyWord.equals(name) && !StringUtils.isEmpty(alias)) {
  30. keyLocation = location;
  31. break;
  32. } else if (name.contains(keyWord)) {
  33. keyLocation = location;
  34. }
  35. }
  36. System.out.println(keyLocation);
  37. }
  38. }

二 测试结果

西京医院

第四军医大学第一附属医院|空军军医大学第一附属医院

108.987693,34.272185


108.987693,34.272185

相关文章