Sab*_*ina 10 java geocoding latitude-longitude
我需要计算给定点的纬度和经度.
我知道参考点的纬度和经度,以及表示距参考点的x和y轴上的米的值.从这些数据开始,我必须找到该点的纬度和经度.
我搜索了类似的问题,但看起来大多数问题都是关于找到两个纬度/长点之间的距离.我需要做相反的事情.
我能怎么做?我用的是Java
Ber*_*ase 11
以下是此类问题的最佳起点:航空处方集.他们拥有做这类事情的所有公式.
从这些处方集中,我创建了自己的Java util类.它使用了很多内部的东西,所以我不能在这里发布实际的类,而是给你一些关于如何将知识从处方集转换为Java代码的例子.
这是一些基本方法:
/**
* the length of one degree of latitude (and one degree of longitude at equator) in meters.
*/
private static final int DEGREE_DISTANCE_AT_EQUATOR = 111329;
/**
* the radius of the earth in meters.
*/
private static final double EARTH_RADIUS = 6378137; //meters
/**
* the length of one minute of latitude in meters, i.e. one nautical mile in meters.
*/
private static final double MINUTES_TO_METERS = 1852d;
/**
* the amount of minutes in one degree.
*/
private static final double DEGREE_TO_MINUTES = 60d;
/**
* This method extrapolates the endpoint of a movement with a given length from a given starting point using a given
* course.
*
* @param startPointLat the latitude of the starting point in degrees, must not be {@link Double#NaN}.
* @param startPointLon the longitude of the starting point in degrees, must not be {@link Double#NaN}.
* @param course the course to be used for extrapolation in degrees, must not be {@link Double#NaN}.
* @param distance the distance to be extrapolated in meters, must not be {@link Double#NaN}.
*
* @return the extrapolated point.
*/
public static Point extrapolate(final double startPointLat, final double startPointLon, final double course,
final double distance) {
//
//lat =asin(sin(lat1)*cos(d)+cos(lat1)*sin(d)*cos(tc))
//dlon=atan2(sin(tc)*sin(d)*cos(lat1),cos(d)-sin(lat1)*sin(lat))
//lon=mod( lon1+dlon +pi,2*pi )-pi
//
// where:
// lat1,lon1 -start pointi n radians
// d - distance in radians Deg2Rad(nm/60)
// tc - course in radians
final double crs = Math.toRadians(course);
final double d12 = Math.toRadians(distance / MINUTES_TO_METERS / DEGREE_TO_MINUTES);
final double lat1 = Math.toRadians(startPointLat);
final double lon1 = Math.toRadians(startPointLon);
final double lat = Math.asin(Math.sin(lat1) * Math.cos(d12)
+ Math.cos(lat1) * Math.sin(d12) * Math.cos(crs));
final double dlon = Math.atan2(Math.sin(crs) * Math.sin(d12) * Math.cos(lat1),
Math.cos(d12) - Math.sin(lat1) * Math.sin(lat));
final double lon = (lon1 + dlon + Math.PI) % (2 * Math.PI) - Math.PI;
return new Point(Math.toDegrees(lat), Math.toDegrees(lon));
}
/**
* calculates the length of one degree of longitude at the given latitude.
*
* @param latitude the latitude to calculate the longitude distance for, must not be {@link Double#NaN}.
*
* @return the length of one degree of longitude at the given latitude in meters.
*/
public static double longitudeDistanceAtLatitude(final double latitude) {
final double longitudeDistanceScaleForCurrentLatitude = Math.cos(Math.toRadians(latitude));
return DEGREE_DISTANCE_AT_EQUATOR * longitudeDistanceScaleForCurrentLatitude;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6597 次 |
| 最近记录: |