我只想找到一个简单的C#类,它在开始的纬度和经度以及距离中找到边界框(最大纬度,最小纬度,最大纬度,最小纬度)。在这里还有其他类似的问题,但他们都没有真正回答这个问题,而那些不在C#中的问题。C#的纬度和经度边界框?
帮助。
我只想找到一个简单的C#类,它在开始的纬度和经度以及距离中找到边界框(最大纬度,最小纬度,最大纬度,最小纬度)。在这里还有其他类似的问题,但他们都没有真正回答这个问题,而那些不在C#中的问题。C#的纬度和经度边界框?
帮助。
这里有你所要求的。感谢Federico A. Ramponi在Python here中编写原创。
public class MapPoint
{
public double Longitude { get; set; } // In Degrees
public double Latitude { get; set; } // In Degrees
}
public class BoundingBox
{
public MapPoint MinPoint { get; set; }
public MapPoint MaxPoint { get; set; }
}
// Semi-axes of WGS-84 geoidal reference
private const double WGS84_a = 6378137.0; // Major semiaxis [m]
private const double WGS84_b = 6356752.3; // Minor semiaxis [m]
// 'halfSideInKm' is the half length of the bounding box you want in kilometers.
public static BoundingBox GetBoundingBox(MapPoint point, double halfSideInKm)
{
// Bounding box surrounding the point at given coordinates,
// assuming local approximation of Earth surface as a sphere
// of radius given by WGS84
var lat = Deg2rad(point.Latitude);
var lon = Deg2rad(point.Longitude);
var halfSide = 1000 * halfSideInKm;
// Radius of Earth at given latitude
var radius = WGS84EarthRadius(lat);
// Radius of the parallel at given latitude
var pradius = radius * Math.Cos(lat);
var latMin = lat - halfSide/radius;
var latMax = lat + halfSide/radius;
var lonMin = lon - halfSide/pradius;
var lonMax = lon + halfSide/pradius;
return new BoundingBox {
MinPoint = new MapPoint { Latitude = Rad2deg(latMin), Longitude = Rad2deg(lonMin) },
MaxPoint = new MapPoint { Latitude = Rad2deg(latMax), Longitude = Rad2deg(lonMax) }
};
}
// degrees to radians
private static double Deg2rad(double degrees)
{
return Math.PI * degrees/180.0;
}
// radians to degrees
private static double Rad2deg(double radians)
{
return 180.0 * radians/Math.PI;
}
// Earth radius at a given latitude, according to the WGS-84 ellipsoid [m]
private static double WGS84EarthRadius(double lat)
{
// http://en.wikipedia.org/wiki/Earth_radius
var An = WGS84_a * WGS84_a * Math.Cos(lat);
var Bn = WGS84_b * WGS84_b * Math.Sin(lat);
var Ad = WGS84_a * Math.Cos(lat);
var Bd = WGS84_b * Math.Sin(lat);
return Math.Sqrt((An*An + Bn*Bn)/(Ad*Ad + Bd*Bd));
}
这里有什么是halfSideInKm? – 2014-07-14 08:25:56
@DharmikBhandari:这是你想要的边界框的一半长度。 – 2014-07-26 17:35:00
我应该通过KM的距离吗? – 2014-07-28 04:48:20
我知道我正在复活一个两年前的问题,但是如果有人从Google来到这里,我已经写了一个C#类库,完成了这一点,并且做了更多。我创建了一个Github repository来承载代码,并将很快撰写一篇博文。
感谢Scott,发现这个代码非常有用。 – 2012-06-01 17:54:34
可能希望查看另一个包装整个Google Maps API的项目,而不仅仅是地理编码:https://github.com/maximnovak/google-maps。可能值得分担 – Pete 2012-06-04 02:54:59
其实这个回购没有利用Google API。它只是使用数学公式来确定距离,方向,边界框等。但是,我有一个相关的Geocoding API(它也在Github上)可以处理地理编码位置。我会检查你提到的回购,但有趣。谢谢! – Scott 2012-06-04 03:00:22
翻阅几篇相关的文章,似乎有足够多的信息和参考资料将您自己的实现在C#中拼凑起来。如果您要求某人为您编写代码,以便您不必这样做,那么您可能在这里没有多少运气。 – 2010-07-16 22:27:23
如果没有特定的帖子链接,我会很乐意忽略你的评论。我已经完成了我的搜索,它不在C# – 2010-07-16 22:35:52
好吧,让我复制本页右侧的第一个相关链接。 http://stackoverflow.com/questions/1648917/given-a-latitude-and-longitude-and-distance-i-want-to-find-a-bounding-box 戳穿那,你会至少要参考Java中的实现,以及关于该问题的数学方法的一些文章。 您可能无法以您偏好的确切语言找到想要的确切实施。我们的想法是获得帮助,思考它,而不是让人们为你思考和编码,然后用第一个编译的类。 – 2010-07-16 22:54:49