|
@@ -1,6 +1,7 @@
|
|
package com.usky.fire.service.util;
|
|
package com.usky.fire.service.util;
|
|
|
|
|
|
//import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
|
//import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
|
|
|
+
|
|
import com.alibaba.nacos.common.utils.StringUtils;
|
|
import com.alibaba.nacos.common.utils.StringUtils;
|
|
import com.fasterxml.jackson.databind.JsonNode;
|
|
import com.fasterxml.jackson.databind.JsonNode;
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
@@ -32,30 +33,31 @@ public class OnlineMethod {
|
|
|
|
|
|
/**
|
|
/**
|
|
* 1.地址转换为经纬度
|
|
* 1.地址转换为经纬度
|
|
|
|
+ *
|
|
* @param address 地址
|
|
* @param address 地址
|
|
* @return 经纬度
|
|
* @return 经纬度
|
|
*/
|
|
*/
|
|
- private static final String GOULD_KEY="2761d6ab4784b2f1de57a787f18c0e46";
|
|
|
|
|
|
+ private static final String GOULD_KEY = "2761d6ab4784b2f1de57a787f18c0e46";
|
|
|
|
|
|
public static List<LocateInfo> getLonLat(String address) {
|
|
public static List<LocateInfo> getLonLat(String address) {
|
|
List<LocateInfo> locateInfos = new ArrayList<>();
|
|
List<LocateInfo> locateInfos = new ArrayList<>();
|
|
try {
|
|
try {
|
|
// 返回输入地址address的经纬度信息, 格式是 经度,纬度
|
|
// 返回输入地址address的经纬度信息, 格式是 经度,纬度
|
|
String encode = URLEncoder.encode(address, "UTF-8");
|
|
String encode = URLEncoder.encode(address, "UTF-8");
|
|
- String queryUrl = "http://restapi.amap.com/v3/geocode/geo?"+"key="+GOULD_KEY+"&address=" + encode+"&batch=true";
|
|
|
|
|
|
+ String queryUrl = "http://restapi.amap.com/v3/geocode/geo?" + "key=" + GOULD_KEY + "&address=" + encode + "&batch=true";
|
|
String queryResult = getResponse(queryUrl);
|
|
String queryResult = getResponse(queryUrl);
|
|
JsonNode arrNode = new ObjectMapper().readTree(queryResult).get("geocodes");
|
|
JsonNode arrNode = new ObjectMapper().readTree(queryResult).get("geocodes");
|
|
if (arrNode.isArray()) {
|
|
if (arrNode.isArray()) {
|
|
for (JsonNode objNode : arrNode) {
|
|
for (JsonNode objNode : arrNode) {
|
|
LocateInfo locateInfo = new LocateInfo();
|
|
LocateInfo locateInfo = new LocateInfo();
|
|
String location = objNode.get("location").asText();
|
|
String location = objNode.get("location").asText();
|
|
- if (StringUtils.isNotBlank(location) && !"[]".equals(location)){
|
|
|
|
|
|
+ if (StringUtils.isNotBlank(location) && !"[]".equals(location)) {
|
|
String[] locations = StringUtils.split(objNode.get("location").asText(), ",");
|
|
String[] locations = StringUtils.split(objNode.get("location").asText(), ",");
|
|
locateInfo.setLongitude(Double.parseDouble(locations[0]));
|
|
locateInfo.setLongitude(Double.parseDouble(locations[0]));
|
|
locateInfo.setLatitude(Double.parseDouble(locations[1]));
|
|
locateInfo.setLatitude(Double.parseDouble(locations[1]));
|
|
locateInfo.setDistrict(objNode.get("district").asText());
|
|
locateInfo.setDistrict(objNode.get("district").asText());
|
|
locateInfo.setStreet(objNode.get("street").asText());
|
|
locateInfo.setStreet(objNode.get("street").asText());
|
|
- }else {
|
|
|
|
|
|
+ } else {
|
|
locateInfo.setLongitude(0.00);
|
|
locateInfo.setLongitude(0.00);
|
|
locateInfo.setLatitude(0.00);
|
|
locateInfo.setLatitude(0.00);
|
|
locateInfo.setDistrict("");
|
|
locateInfo.setDistrict("");
|
|
@@ -64,14 +66,33 @@ public class OnlineMethod {
|
|
locateInfos.add(locateInfo);
|
|
locateInfos.add(locateInfo);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- }catch (Exception e){
|
|
|
|
|
|
+ } catch (Exception e) {
|
|
log.error(e.getMessage());
|
|
log.error(e.getMessage());
|
|
}
|
|
}
|
|
return locateInfos;
|
|
return locateInfos;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+
|
|
|
|
+ public static String getStreetTown(String location) {
|
|
|
|
+ String streetTown = null;
|
|
|
|
+ try {
|
|
|
|
+ // 返回输入地址address的经纬度信息, 格式是 经度,纬度
|
|
|
|
+ String encode = URLEncoder.encode(location, "UTF-8");
|
|
|
|
+ String queryUrl = "http://restapi.amap.com/v3/geocode/regeo?" + "key=" + GOULD_KEY + "&location=" + encode + "";
|
|
|
|
+ String queryResult = getResponse(queryUrl);
|
|
|
|
+ JsonNode arrNode = new ObjectMapper().readTree(queryResult).get("regeocode");
|
|
|
|
+ JsonNode addressComponent = arrNode.get("addressComponent");
|
|
|
|
+ streetTown = addressComponent.get("township").toString();
|
|
|
|
+ streetTown = streetTown.replace("\"","");
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ log.error(e.getMessage());
|
|
|
|
+ }
|
|
|
|
+ return streetTown;
|
|
|
|
+ }
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 3.发送请求
|
|
* 3.发送请求
|
|
|
|
+ *
|
|
* @param serverUrl 请求地址
|
|
* @param serverUrl 请求地址
|
|
*/
|
|
*/
|
|
private static String getResponse(String serverUrl) {
|
|
private static String getResponse(String serverUrl) {
|