polygon.Locations 是定义多边形的点列表。
您必须制定一种方法来确定您的点是否在多边形内。
使用这样的东西(如果编译没有测试):
static bool PointInPolygon(LocationCollection polyPoints, Location point)
{
if (polyPoints.Length < 3)
{
return false;
}
bool inside = false;
Location p1, p2;
//iterate each side of the polygon
Location oldPoint = polyPoints[polyPoints.Count - 1];
foreach(Location newPoint in polyPoints)
{
//order points so p1.lat <= p2.lat;
if (newPoint.Latitude > oldPoint.Latitude)
{
p1 = oldPoint;
p2 = newPoint;
}
else
{
p1 = newPoint;
p2 = oldPoint;
}
//test if the line is crossed and if so invert the inside flag.
if ((newPoint.Latitude < point.Latitude) == (point.Latitude <= oldPoint.Latitude)
&& (point.Longitude - p1.Longitude) * (p2.Latitude - p1.Latitude)
< (p2.Longitude - p1.Longitude) * (point.Latitude - p1.Latitude))
{
inside = !inside;
}
oldPoint = newPoint;
}
return inside;
}
并这样称呼它:
if (PointInPolygon(polygon.Locations, new Location(this.Site.Latitude, this.Site.Longitude, this.Site.Altitude)))
{
//do something
}