diff --git a/src/main/java/com/xkrs/model/bean/AddressBean.java b/src/main/java/com/xkrs/model/bean/AddressBean.java index 1f7d161..cca01d7 100644 --- a/src/main/java/com/xkrs/model/bean/AddressBean.java +++ b/src/main/java/com/xkrs/model/bean/AddressBean.java @@ -7,6 +7,11 @@ public class AddressBean { */ private boolean success; + /** + * 消息 + */ + private String message; + /** * 省的编码 */ @@ -63,6 +68,14 @@ public class AddressBean { this.success = success; } + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + public String getProCode() { return proCode; } @@ -139,6 +152,7 @@ public class AddressBean { public String toString() { return "AddressBean{" + "success=" + success + + ", message='" + message + '\'' + ", proCode='" + proCode + '\'' + ", proName='" + proName + '\'' + ", cityCode='" + cityCode + '\'' + diff --git a/src/main/java/com/xkrs/utilsnew/FirePointAddressUtils.java b/src/main/java/com/xkrs/utilsnew/FirePointAddressUtils.java index 7e572fd..77c233b 100644 --- a/src/main/java/com/xkrs/utilsnew/FirePointAddressUtils.java +++ b/src/main/java/com/xkrs/utilsnew/FirePointAddressUtils.java @@ -1,6 +1,7 @@ package com.xkrs.utilsnew; import cn.hutool.core.util.StrUtil; +import com.alibaba.fastjson.JSON; import com.xkrs.model.bean.AddressBean; import com.xkrs.model.vo.TianDiTuGeocodeVo; import org.apache.hc.core5.util.TextUtils; @@ -14,12 +15,15 @@ public class FirePointAddressUtils { * 使用网络方式解析地址信息 */ public static AddressBean analysisWithNetwork(double longitude, double latitude) { + AddressBean addressBean = new AddressBean(); + String geocodeStr = ""; try { TianDiTuGeocodeVo geocode = TianDiTuApiUtil.geocode(longitude, latitude); + geocodeStr = JSON.toJSONString(geocode); TianDiTuGeocodeVo.ResultDTO.AddressComponentDTO addressComponent = geocode.result.addressComponent; //填充AddressBean数据 - AddressBean addressBean = new AddressBean(); addressBean.setSuccess(true); + addressBean.setMessage(""); addressBean.setProCode(StrUtil.isEmpty(addressComponent.provinceCode) ? "" : addressComponent.provinceCode.substring(3, 9)); addressBean.setProName(addressComponent.province); addressBean.setCityCode(StrUtil.isEmpty(addressComponent.cityCode) ? "" : addressComponent.cityCode.substring(3, 9)); @@ -32,10 +36,10 @@ public class FirePointAddressUtils { return addressBean; } catch (Exception e) { e.printStackTrace(); + addressBean.setSuccess(false); + addressBean.setMessage("longitude=" + longitude + ",latitude=" + latitude + ",geocode=" + geocodeStr + ",message=" + e.getMessage()); + return addressBean; } - AddressBean addressBean = new AddressBean(); - addressBean.setSuccess(false); - return addressBean; } /** @@ -72,7 +76,7 @@ public class FirePointAddressUtils { } public static void main(String[] args) { - AddressBean addressBean = analysisWithNetwork(120.98, 36.78); + AddressBean addressBean = analysisWithNetwork(109.6981278, 19.8897095); System.out.println(addressBean.toString()); }