我正在使用 Android
MapView
并开发基于 map 的应用程序。我需要找到与特定 坐标
的 X 距离。方向不是我的首要任务距离是我的首要任务让我说我需要找到距离特定位置 100 米的任何想法我该怎么做
提前感谢您的阅读和回答。
最佳答案
为了通过计算找到距原点给定距离的直线上的点,您需要有方位(或方向)以及距离。这是一个函数,它将获取起始位置、方位角和距离(深度)并返回目的地位置(适用于 Android):您可能希望将其从 KM 转换为米或其他任何格式。
public static Location GetDestinationPoint(Location startLoc, float bearing, float depth)
{
Location newLocation = new Location("newLocation");
double radius = 6371.0; // earth's mean radius in km
double lat1 = Math.toRadians(startLoc.getLatitude());
double lng1 = Math.toRadians(startLoc.getLongitude());
double brng = Math.toRadians(bearing);
double lat2 = Math.asin( Math.sin(lat1)*Math.cos(depth/radius) + Math.cos(lat1)*Math.sin(depth/radius)*Math.cos(brng) );
double lng2 = lng1 + Math.atan2(Math.sin(brng)*Math.sin(depth/radius)*Math.cos(lat1), Math.cos(depth/radius)-Math.sin(lat1)*Math.sin(lat2));
lng2 = (lng2+Math.PI)%(2*Math.PI) - Math.PI;
// normalize to -180...+180
if (lat2 == 0 || lng2 == 0)
{
newLocation.setLatitude(0.0);
newLocation.setLongitude(0.0);
}
else
{
newLocation.setLatitude(Math.toDegrees(lat2));
newLocation.setLongitude(Math.toDegrees(lng2));
}
return newLocation;
};
关于Android从定义的位置查找X点的纬度经度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14332348/