Abo*_*evo 3 bing-maps silverlight-4.0 c#-4.0
我有一个bing地图,还有两点:Point1,Point2和我想计算这两点之间的距离?那可能吗?如果我想在point1和point2之间以及point2附近的路径的三分之一处放一个圆圈......我怎么能做到?
pse*_*udo 12
Microsoft有一个GeoCoordinate.GetDistanceTo方法,它使用Haversine公式.
对我来说,其他实现返回NaN的距离太小.我还没有遇到内置函数的任何问题.
Bea*_*ker 10
看看Haversine甚至更好的Vincenty公式如何解决这个问题.
以下代码使用hasrsines方法来获取距离:
public double GetDistanceBetweenPoints(double lat1, double long1, double lat2, double long2)
{
double distance = 0;
double dLat = (lat2 - lat1) / 180* Math.PI;
double dLong = (long2 - long1) / 180 * Math.PI;
double a = Math.Sin(dLat / 2) * Math.Sin(dLat / 2)
+ Math.Cos(lat1 / 180* Math.PI) * Math.Cos(lat2 / 180* Math.PI)
* Math.Sin(dLong/2) * Math.Sin(dLong/2);
double c = 2 * Math.Atan2(Math.Sqrt(a), Math.Sqrt(1 - a));
//Calculate radius of earth
// For this you can assume any of the two points.
double radiusE = 6378135; // Equatorial radius, in metres
double radiusP = 6356750; // Polar Radius
//Numerator part of function
double nr = Math.Pow(radiusE * radiusP * Math.Cos(lat1 / 180 * Math.PI), 2);
//Denominator part of the function
double dr = Math.Pow(radiusE * Math.Cos(lat1 / 180 * Math.PI), 2)
+ Math.Pow(radiusP * Math.Sin(lat1 / 180 * Math.PI), 2);
double radius = Math.Sqrt(nr / dr);
//Calculate distance in meters.
distance = radius * c;
return distance; // distance in meters
}
Run Code Online (Sandbox Code Playgroud)
你可以在这里找到一个有信息的好网站.
| 归档时间: |
|
| 查看次数: |
17544 次 |
| 最近记录: |