parent
0c88fcad74
commit
48c6bc0f7e
5 changed files with 111 additions and 25 deletions
@ -0,0 +1,44 @@ |
||||
package com.hisense.hiatmp.server_api.utils; |
||||
|
||||
import java.math.BigDecimal; |
||||
|
||||
public class CoordinateUtils { |
||||
|
||||
// 地球半径(km)
|
||||
private static final double EARTH_RADIUS = 6371.0; |
||||
|
||||
/** |
||||
* 获取指定距离范围内的矩形坐标 |
||||
* @param lat 纬度 |
||||
* @param lon 经度 |
||||
* @param distance 距离(公里) |
||||
* @return 矩形坐标范围(最小经度, 最小纬度, 最大经度, 最大纬度) |
||||
*/ |
||||
public static double[] getRectangleCoordinates(double lat, double lon, double distance) { |
||||
double latRad = Math.toRadians(lat); |
||||
double lonRad = Math.toRadians(lon); |
||||
|
||||
// 纬度范围计算
|
||||
double latMin = latRad - Math.asin(Math.sin(distance / (EARTH_RADIUS * Math.cos(latRad))) / Math.cos(distance / EARTH_RADIUS)); |
||||
double latMax = latRad + Math.asin(Math.sin(distance / (EARTH_RADIUS * Math.cos(latRad))) / Math.cos(distance / EARTH_RADIUS)); |
||||
|
||||
// 经度范围计算
|
||||
double lonMin = lonRad - Math.atan2(Math.sin(distance / EARTH_RADIUS) * Math.cos(latRad), Math.cos(distance / EARTH_RADIUS) - Math.sin(latRad) * Math.sin(latMin)); |
||||
double lonMax = lonRad + Math.atan2(Math.sin(distance / EARTH_RADIUS) * Math.cos(latRad), Math.cos(distance / EARTH_RADIUS) - Math.sin(latRad) * Math.sin(latMax)); |
||||
|
||||
return new double[]{ |
||||
Math.toDegrees(lonMin), |
||||
Math.toDegrees(latMin), |
||||
Math.toDegrees(lonMax), |
||||
Math.toDegrees(latMax) |
||||
}; |
||||
} |
||||
|
||||
public static void main(String[] args) { |
||||
/*double[] rectangle = getRectangleCoordinates(39.910922, 116.401735, 3); // 北京天安门坐标,3公里范围
|
||||
System.out.println("最小经度: " + rectangle[0]); |
||||
System.out.println("最小纬度: " + rectangle[1]); |
||||
System.out.println("最大经度: " + rectangle[2]); |
||||
System.out.println("最大纬度: " + rectangle[3]);*/ |
||||
} |
||||
} |
||||
Loading…
Reference in new issue