Max*_*lli 11 c# maps coordinates
我有一个点列表(实际上是商店坐标),我需要确定它们是否位于某些边界内.
在C#中我知道如何从lat&lng创建一个点
var point = new GeoCoordinate(latitude, longitude);
Run Code Online (Sandbox Code Playgroud)
但是,如何检查该点是否包含在由其他两点定义的矩形中:
var swPoint = new GeoCoordinate(bounds.swlat, bounds.swlng);
var nePoint = new GeoCoordinate(bounds.nelat, bounds.nelng);
Run Code Online (Sandbox Code Playgroud)
我可以使用任何课程方法吗?
phi*_*gon 12
如果您使用的是 http://msdn.microsoft.com/en-us/library/system.device.location.geocoordinate.aspx
您必须编写自己的方法来进行此检查.您可能希望将其作为扩展方法(在线扩展方法可用的资源数量.)
然后它几乎一样简单
public static Boolean isWithin(this GeoCoordinate pt, GeoCoordinate sw, GeoCoordinate ne)
{
return pt.Latitude >= sw.Latitude &&
pt.Latitude <= ne.Latitude &&
pt.Longitude >= sw.Longitude &&
pt.Longitude <= ne.Longitude
}
Run Code Online (Sandbox Code Playgroud)
有一个角落需要考虑.如果sw,ne定义的框穿过180度经度,则上述方法将失败.因此,必须编写额外的代码来覆盖该情况,从而降低该方法的性能.
归档时间: |
|
查看次数: |
6140 次 |
最近记录: |