|
|
@ -920,45 +920,45 @@ public class DcTrafficStatisticsServiceImpl implements IDcTrafficStatisticsServi |
|
|
|
Response response // 请求响应
|
|
|
|
= okHttp |
|
|
|
.headers(headers) |
|
|
|
.url(baseUrl + "/api/dc/query/rd_tr_congestion_jh") // 请求地址
|
|
|
|
.url(baseUrl + UniversalEnum.GETS_THE_URI_OF_THE_CURRENT_CONGESTION_EVENT.getValue()) // 请求地址
|
|
|
|
.data(requestParams) // 请求参数
|
|
|
|
.post(); // 请求方法
|
|
|
|
|
|
|
|
ResponseBody body = response.body(); |
|
|
|
if (body != null) { |
|
|
|
JSONArray jsonArray = JSON.parseArray(body.string()); |
|
|
|
JSONObject jsonObject = (JSONObject) jsonArray.get(0); |
|
|
|
JSONObject jsonObject = (JSONObject) jsonArray.get(UniversalEnum.ZERO.getNumber()); |
|
|
|
Integer asOneRoad = jsonObject.getInteger("as_one_road"); |
|
|
|
|
|
|
|
if (asOneRoad == UniversalEnum.ONE.getNumber()){ |
|
|
|
|
|
|
|
String string = jsonObject.getString("list_link_info"); |
|
|
|
JSONArray jsonlist = JSON.parseArray(string); |
|
|
|
JSONObject o = (JSONObject) jsonlist.get(0); |
|
|
|
JSONObject o = (JSONObject) jsonlist.get(UniversalEnum.ZERO.getNumber()); |
|
|
|
|
|
|
|
String string1 = o.getString("firstPoint"); |
|
|
|
String string2 = o.getString("lastPoint"); |
|
|
|
String lngLats = o.getString("lngLats"); |
|
|
|
String[] lngLatsString = lngLats.split(";"); |
|
|
|
double s = Double.parseDouble(lngLatsString[0].split(",")[0]); |
|
|
|
double s2 = Double.parseDouble(lngLatsString[0].split(",")[1]); |
|
|
|
double s3 = Double.parseDouble(lngLatsString[lngLatsString.length-1].split(",")[0]); |
|
|
|
double s4 = Double.parseDouble(lngLatsString[lngLatsString.length-1].split(",")[1]); |
|
|
|
double distanceM = calculateDistance(s2, s, s4, s3)* 1000; |
|
|
|
String[] lngLatsString = lngLats.split(UniversalEnum.COLON.getValue()); |
|
|
|
double s = Double.parseDouble(lngLatsString[UniversalEnum.ZERO.getNumber()].split(UniversalEnum.COMMA.getValue())[UniversalEnum.ZERO.getNumber()]); |
|
|
|
double s2 = Double.parseDouble(lngLatsString[UniversalEnum.ZERO.getNumber()].split(UniversalEnum.COMMA.getValue())[UniversalEnum.ONE.getNumber()]); |
|
|
|
double s3 = Double.parseDouble(lngLatsString[lngLatsString.length-UniversalEnum.ONE.getNumber()].split(UniversalEnum.COMMA.getValue())[UniversalEnum.ZERO.getNumber()]); |
|
|
|
double s4 = Double.parseDouble(lngLatsString[lngLatsString.length-UniversalEnum.ONE.getNumber()].split(UniversalEnum.COMMA.getValue())[UniversalEnum.ONE.getNumber()]); |
|
|
|
double distanceM = calculateDistance(s2, s, s4, s3)* UniversalEnum.THOUSAND.getNumber(); |
|
|
|
// System.out.printf("最大距离为: %.2f 米%n", distanceM);
|
|
|
|
jsonObject.put("max_jam_dist",distanceM);//最大拥堵距离
|
|
|
|
String[] split = string1.split(","); |
|
|
|
double firstLon = Double.parseDouble(split[0]); |
|
|
|
double firstLat = Double.parseDouble(split[1]); |
|
|
|
String[] split2 = string2.split(","); |
|
|
|
double lastLon = Double.parseDouble(split2[0]); |
|
|
|
double lastLat = Double.parseDouble(split2[1]); |
|
|
|
String[] split = string1.split(UniversalEnum.COMMA.getValue()); |
|
|
|
double firstLon = Double.parseDouble(split[UniversalEnum.ZERO.getNumber()]); |
|
|
|
double firstLat = Double.parseDouble(split[UniversalEnum.ONE.getNumber()]); |
|
|
|
String[] split2 = string2.split(UniversalEnum.COMMA.getValue()); |
|
|
|
double lastLon = Double.parseDouble(split2[UniversalEnum.ZERO.getNumber()]); |
|
|
|
double lastLat = Double.parseDouble(split2[UniversalEnum.ONE.getNumber()]); |
|
|
|
//double firstLat = 35.38524527319016;
|
|
|
|
// double firstLon = 118.39808642864227;
|
|
|
|
//double lastLat = 35.386351346969604;
|
|
|
|
// double lastLon = 118.4038907289505;
|
|
|
|
double distanceKm = calculateDistance(firstLat, firstLon, lastLat, lastLon); |
|
|
|
double distanceMeters = distanceKm * 1000; // 将距离转换为米
|
|
|
|
double distanceMeters = distanceKm * UniversalEnum.THOUSAND.getNumber(); // 将距离转换为米
|
|
|
|
//System.out.printf("两点之间的距离为: %.2f 米%n", distanceMeters);
|
|
|
|
jsonObject.put("jam_dist",distanceMeters);//当前拥堵距离
|
|
|
|
|
|
|
@ -1012,10 +1012,10 @@ public class DcTrafficStatisticsServiceImpl implements IDcTrafficStatisticsServi |
|
|
|
double dLon = endLonRad - startLonRad; |
|
|
|
|
|
|
|
// Haversine公式
|
|
|
|
double a = Math.pow(Math.sin(dLat / 2), 2) + |
|
|
|
double a = Math.pow(Math.sin(dLat / UniversalEnum.TWO.getNumber()), UniversalEnum.TWO.getNumber()) + |
|
|
|
Math.cos(startLatRad) * Math.cos(endLatRad) * |
|
|
|
Math.pow(Math.sin(dLon / 2), 2); |
|
|
|
double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a)); |
|
|
|
Math.pow(Math.sin(dLon / UniversalEnum.TWO.getNumber()), UniversalEnum.TWO.getNumber()); |
|
|
|
double c = UniversalEnum.TWO.getNumber() * Math.atan2(Math.sqrt(a), Math.sqrt(UniversalEnum.ONE.getNumber() - a)); |
|
|
|
|
|
|
|
// 计算两点间的距离
|
|
|
|
double distance = EARTH_RADIUS * c; |
|
|
|