我正在开发一款使用Geopoints的Android应用程序,我想从另一个Geopoint确定一个Geopoint,一个距离(任何格式)和一个极角。例如,我希望通过手机中的GPS获取我所在位置的北 - 东北(22,5度)100米处的坐标。
我找到的唯一方法是Location.distanceBetween(...)
。
答案 0 :(得分:4)
Android的实施。此代码非常适合您的应用程序中的单元测试:
public double radiansFromDegrees(double degrees)
{
return degrees * (Math.PI/180.0);
}
public double degreesFromRadians(double radians)
{
return radians * (180.0/Math.PI);
}
public Location locationFromLocation(Location fromLocation, double distance, double bearingDegrees)
{
double distanceKm = distance / 1000.0;
double distanceRadians = distanceKm / 6371.0;
//6,371 = Earth's radius in km
double bearingRadians = this.radiansFromDegrees(bearingDegrees);
double fromLatRadians = this.radiansFromDegrees(fromLocation.getLatitude());
double fromLonRadians = this.radiansFromDegrees(fromLocation.getLongitude());
double toLatRadians = Math.asin( Math.sin(fromLatRadians) * Math.cos(distanceRadians)
+ Math.cos(fromLatRadians) * Math.sin(distanceRadians) * Math.cos(bearingRadians) );
double toLonRadians = fromLonRadians + Math.atan2(Math.sin(bearingRadians)
* Math.sin(distanceRadians) * Math.cos(fromLatRadians), Math.cos(distanceRadians)
- Math.sin(fromLatRadians) * Math.sin(toLatRadians));
// adjust toLonRadians to be in the range -180 to +180...
toLonRadians = ((toLonRadians + 3*Math.PI) % (2*Math.PI) ) - Math.PI;
Location result = new Location(LocationManager.GPS_PROVIDER);
result.setLatitude(this.degreesFromRadians(toLatRadians));
result.setLongitude(this.degreesFromRadians(toLonRadians));
return result;
}
答案 1 :(得分:1)
看看大圆公式:http://en.wikipedia.org/wiki/Great-circle_distance
这应该给你一些关于如何计算距离的提示。
对于给定距离和标题中的点,请检查http://williams.best.vwh.net/avform.htm#LL 这些公式看起来很复杂,但很容易实现;)