计算距离另一个纬度/经度点的米距离的纬度和经度 [英] Calculate latitude and longitude having meters distance from another latitude/longitude point
问题描述
我需要计算给定点的纬度和经度。
I need to calculate latitude and longitude of a given point.
我知道参考点的纬度和经度,以及表示参考点x和y轴上的米的值。
从这些数据开始,我必须找到该点的纬度和经度。
I know latitude and longitude of a reference point, and an value indicating meters on x and y axis from the reference point. Starting from this data I have to find latitude and longitude of the point.
我搜索了类似的问题,但看起来大多数问题都是关于寻找距离两个纬度/长点。我需要做相反的事情。
I searched for similar questions but it looks like most questions are about finding distance between two lat/long points. I need to do the contrary.
我该怎么办?
我使用Java
How can I do? I use Java
推荐答案
以下是此类问题的最佳起点:航空处方集。他们拥有做这类事情的所有公式。
Here is the best starting point for such questions: Aviation Formulary. They have all the formulas for doing such kinds of things.
从这些处方集中,我创建了自己的Java util类。它使用了很多内部的东西,所以我不能在这里发布实际的类,而是给你一些关于如何将知识从处方集转换为Java代码的例子。
From these formulary, I created my own Java util class. It uses a lot of internal stuff, so I cannot post the actual class here but to give you some examples on how to convert the knowledge from the formulary into Java code.
以下是一些基本方法:
/**
* 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;
}
这篇关于计算距离另一个纬度/经度点的米距离的纬度和经度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!