Biz_ext
package hospital;
import java.util.List;
public class Biz_ext {
private List<String> cost;
private List<String> rating;
public void setCost(List<String> cost) {
this.cost = cost;
}
public List<String> getCost() {
return cost;
}
public void setRating(List<String> rating) {
this.rating = rating;
}
public List<String> getRating() {
return rating;
}
}
Children
package hospital;
public class Children {
private String typecode;
private String address;
private String distance;
private String subtype;
private String sname;
private String name;
private String location;
private String id;
public void setTypecode(String typecode) {
this.typecode = typecode;
}
public String getTypecode() {
return typecode;
}
public void setAddress(String address) {
this.address = address;
}
public String getAddress() {
return address;
}
public void setDistance(String distance) {
this.distance = distance;
}
public String getDistance() {
return distance;
}
public void setSubtype(String subtype) {
this.subtype = subtype;
}
public String getSubtype() {
return subtype;
}
public void setSname(String sname) {
this.sname = sname;
}
public String getSname() {
return sname;
}
public void setName(String name) {
this.name = name;
}
public String getName() {
return name;
}
public void setLocation(String location) {
this.location = location;
}
public String getLocation() {
return location;
}
public void setId(String id) {
this.id = id;
}
public String getId() {
return id;
}
}
HospitalResponse
package hospital;
import java.util.List;
public class HospitalResponse {
private Suggestion suggestion;
private String count;
private String infocode;
private List<Pois> pois;
private String status;
private String info;
public void setSuggestion(Suggestion suggestion) {
this.suggestion = suggestion;
}
public Suggestion getSuggestion() {
return suggestion;
}
public void setCount(String count) {
this.count = count;
}
public String getCount() {
return count;
}
public void setInfocode(String infocode) {
this.infocode = infocode;
}
public String getInfocode() {
return infocode;
}
public void setPois(List<Pois> pois) {
this.pois = pois;
}
public List<Pois> getPois() {
return pois;
}
public void setStatus(String status) {
this.status = status;
}
public String getStatus() {
return status;
}
public void setInfo(String info) {
this.info = info;
}
public String getInfo() {
return info;
}
}
Indoor_data
package hospital;
import java.util.List;
public class Indoor_data {
private List<String> cmsid;
private List<String> truefloor;
private List<String> cpid;
private List<String> floor;
public void setCmsid(List<String> cmsid) {
this.cmsid = cmsid;
}
public List<String> getCmsid() {
return cmsid;
}
public void setTruefloor(List<String> truefloor) {
this.truefloor = truefloor;
}
public List<String> getTruefloor() {
return truefloor;
}
public void setCpid(List<String> cpid) {
this.cpid = cpid;
}
public List<String> getCpid() {
return cpid;
}
public void setFloor(List<String> floor) {
this.floor = floor;
}
public List<String> getFloor() {
return floor;
}
}
Photos
package hospital;
import java.util.List;
public class Photos {
private List<String> title;
private String url;
public void setTitle(List<String> title) {
this.title = title;
}
public List<String> getTitle() {
return title;
}
public void setUrl(String url) {
this.url = url;
}
public String getUrl() {
return url;
}
}
Pois
package hospital;
import java.util.Date;
import java.util.List;
public class Pois {
private List<String> parent;
private List<String> distance;
private String pcode;
private List<String> importance;
private Biz_ext biz_ext;
private String recommend;
private String type;
private List<Photos> photos;
private String discount_num;
private String gridcode;
private String typecode;
private String shopinfo;
private List<String> poiweight;
private String citycode;
private String adname;
private List<Children> children;
private String alias;
private String tel;
private String id;
private String tag;
private List<String> event;
private String entr_location;
private String indoor_map;
private List<String> email;
private Date timestamp;
private String website;
private String address;
private String adcode;
private String pname;
private List<String> biz_type;
private String cityname;
private List<String> postcode;
private String match;
private String business_area;
private Indoor_data Indoor_data;
private List<String> childtype;
private List<String> exit_location;
private String name;
private String location;
private List<String> shopid;
private String navi_poiid;
private String groupbuy_num;
public void setParent(List<String> parent) {
this.parent = parent;
}
public List<String> getParent() {
return parent;
}
public void setDistance(List<String> distance) {
this.distance = distance;
}
public List<String> getDistance() {
return distance;
}
public void setPcode(String pcode) {
this.pcode = pcode;
}
public String getPcode() {
return pcode;
}
public void setImportance(List<String> importance) {
this.importance = importance;
}
public List<String> getImportance() {
return importance;
}
public void setBiz_ext(Biz_ext biz_ext) {
this.biz_ext = biz_ext;
}
public Biz_ext getBiz_ext() {
return biz_ext;
}
public void setRecommend(String recommend) {
this.recommend = recommend;
}
public String getRecommend() {
return recommend;
}
public void setType(String type) {
this.type = type;
}
public String getType() {
return type;
}
public void setPhotos(List<Photos> photos) {
this.photos = photos;
}
public List<Photos> getPhotos() {
return photos;
}
public void setDiscount_num(String discount_num) {
this.discount_num = discount_num;
}
public String getDiscount_num() {
return discount_num;
}
public void setGridcode(String gridcode) {
this.gridcode = gridcode;
}
public String getGridcode() {
return gridcode;
}
public void setTypecode(String typecode) {
this.typecode = typecode;
}
public String getTypecode() {
return typecode;
}
public void setShopinfo(String shopinfo) {
this.shopinfo = shopinfo;
}
public String getShopinfo() {
return shopinfo;
}
public void setPoiweight(List<String> poiweight) {
this.poiweight = poiweight;
}
public List<String> getPoiweight() {
return poiweight;
}
public void setCitycode(String citycode) {
this.citycode = citycode;
}
public String getCitycode() {
return citycode;
}
public void setAdname(String adname) {
this.adname = adname;
}
public String getAdname() {
return adname;
}
public void setChildren(List<Children> children) {
this.children = children;
}
public List<Children> getChildren() {
return children;
}
public void setAlias(String alias) {
this.alias = alias;
}
public String getAlias() {
return alias;
}
public void setTel(String tel) {
this.tel = tel;
}
public String getTel() {
return tel;
}
public void setId(String id) {
this.id = id;
}
public String getId() {
return id;
}
public void setTag(String tag) {
this.tag = tag;
}
public String getTag() {
return tag;
}
public void setEvent(List<String> event) {
this.event = event;
}
public List<String> getEvent() {
return event;
}
public void setEntr_location(String entr_location) {
this.entr_location = entr_location;
}
public String getEntr_location() {
return entr_location;
}
public void setIndoor_map(String indoor_map) {
this.indoor_map = indoor_map;
}
public String getIndoor_map() {
return indoor_map;
}
public void setEmail(List<String> email) {
this.email = email;
}
public List<String> getEmail() {
return email;
}
public void setTimestamp(Date timestamp) {
this.timestamp = timestamp;
}
public Date getTimestamp() {
return timestamp;
}
public void setWebsite(String website) {
this.website = website;
}
public String getWebsite() {
return website;
}
public void setAddress(String address) {
this.address = address;
}
public String getAddress() {
return address;
}
public void setAdcode(String adcode) {
this.adcode = adcode;
}
public String getAdcode() {
return adcode;
}
public void setPname(String pname) {
this.pname = pname;
}
public String getPname() {
return pname;
}
public void setBiz_type(List<String> biz_type) {
this.biz_type = biz_type;
}
public List<String> getBiz_type() {
return biz_type;
}
public void setCityname(String cityname) {
this.cityname = cityname;
}
public String getCityname() {
return cityname;
}
public void setPostcode(List<String> postcode) {
this.postcode = postcode;
}
public List<String> getPostcode() {
return postcode;
}
public void setMatch(String match) {
this.match = match;
}
public String getMatch() {
return match;
}
public void setBusiness_area(String business_area) {
this.business_area = business_area;
}
public String getBusiness_area() {
return business_area;
}
public void setIndoor_data(Indoor_data indoor_data) {
this.Indoor_data = indoor_data;
}
public Indoor_data getIndoor_data() {
return Indoor_data;
}
public void setChildtype(List<String> childtype) {
this.childtype = childtype;
}
public List<String> getChildtype() {
return childtype;
}
public void setExit_location(List<String> exit_location) {
this.exit_location = exit_location;
}
public List<String> getExit_location() {
return exit_location;
}
public void setName(String name) {
this.name = name;
}
public String getName() {
return name;
}
public void setLocation(String location) {
this.location = location;
}
public String getLocation() {
return location;
}
public void setShopid(List<String> shopid) {
this.shopid = shopid;
}
public List<String> getShopid() {
return shopid;
}
public void setNavi_poiid(String navi_poiid) {
this.navi_poiid = navi_poiid;
}
public String getNavi_poiid() {
return navi_poiid;
}
public void setGroupbuy_num(String groupbuy_num) {
this.groupbuy_num = groupbuy_num;
}
public String getGroupbuy_num() {
return groupbuy_num;
}
}
Suggestion
package hospital;
import java.util.List;
public class Suggestion {
private List<String> keywords;
private List<String> cities;
public void setKeywords(List<String> keywords) {
this.keywords = keywords;
}
public List<String> getKeywords() {
return keywords;
}
public void setCities(List<String> cities) {
this.cities = cities;
}
public List<String> getCities() {
return cities;
}
}
package hospital;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.ParseException;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;
import java.io.IOException;
/**
* @className: HttpClientUtils
* @description: 本工具采用的是最新的 HttpComponents-Client-4.2.1 ,封装了一些采用 HttpClient 发送 HTTP 请求的方法
* @date: 2021/2/10
* @author: cakin
*/
public class HttpClientUtils {
private static Log logger = LogFactory.getLog(hospital.HttpClientUtils.class);
private HttpClientUtils() {
}
/**
* 发送HTTP_GET请求
*
* @param reqURL 请求地址(含参数)
* @param decodeCharset 解码字符集,解析响应数据时用之,其为null时默认采用UTF-8解码
* @return 远程主机响应正文
*/
public static String sendGetRequest(String reqURL, String decodeCharset) {
long responseLength = 0; //响应长度
String responseContent = null; //响应内容
HttpClient httpClient = new DefaultHttpClient(); //创建默认的httpClient实例
HttpGet httpGet = new HttpGet(reqURL); //创建org.apache.http.client.methods.HttpGet
try {
HttpResponse response = httpClient.execute(httpGet); //执行GET请求
HttpEntity entity = response.getEntity(); //获取响应实体
if (null != entity) {
responseLength = entity.getContentLength();
responseContent = EntityUtils.toString(entity, decodeCharset == null ? "UTF-8" : decodeCharset);
EntityUtils.consume(entity); //Consume response content
}
System.out.println("请求地址: " + httpGet.getURI());
System.out.println("响应状态: " + response.getStatusLine());
System.out.println("响应长度: " + responseLength);
System.out.println("响应内容: " + responseContent);
} catch (ClientProtocolException e) {
logger.debug("该异常通常是协议错误导致,比如构造HttpGet对象时传入的协议不对(将'http'写成'htp')或者服务器端返回的内容不符合HTTP协议要求等,堆栈信息如下", e);
} catch (ParseException e) {
logger.debug(e.getMessage(), e);
} catch (IOException e) {
logger.debug("该异常通常是网络原因引起的,如HTTP服务器未启动等,堆栈信息如下", e);
} finally {
httpClient.getConnectionManager().shutdown(); //关闭连接,释放资源
}
return responseContent;
}
}
package hospital;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import org.apache.commons.lang3.StringUtils;
/**
* @className: Test
* @description: 求某个医院的近似经纬度,参考 https://lbs.amap.com/api/webservice/guide/api/search
* @date: 2022/6/2
* @author: cakin
*/
public class Test {
public static void main(String[] args) {
String keyWord = "西京医院";
String reqURL = "https://restapi.amap.com/v3/place/text?key=019283b6XXXXe7499f4ec877f5ab&keywords=" + keyWord + "&types=&city=&children=1&offset=1000&page=1&extensions=all";
String result = HttpClientUtils.sendGetRequest(reqURL, null);
JSONObject jsonObject = JSON.parseObject(result);
JSONArray arrayObj = jsonObject.getJSONArray("pois");
String keyLocation = "";
for (int i = 0; i < arrayObj.size(); i++) {
JSONObject poisObject = arrayObj.getJSONObject(i);
String location = poisObject.getString("location");
String name = poisObject.getString("name");
String alias = poisObject.getString("alias");
System.out.println(name);
System.out.println(alias);
System.out.println(location);
System.out.println("--------------");
if (keyWord.equals(name) && !StringUtils.isEmpty(alias)) {
keyLocation = location;
break;
} else if (name.contains(keyWord)) {
keyLocation = location;
}
}
System.out.println(keyLocation);
}
}
西京医院
第四军医大学第一附属医院|空军军医大学第一附属医院
108.987693,34.272185
108.987693,34.272185
版权说明 : 本文为转载文章, 版权归原作者所有 版权申明
原文链接 : https://blog.csdn.net/chengqiuming/article/details/125094587
内容来源于网络,如有侵权,请联系作者删除!