的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
}
這聽起來像你想使用光線投射算法。 http://en.wikipedia.org/wiki/Point_in_polygon#Ray_casting_algorithm 對不起,我不能幫助不止於此。我不熟悉Bing地圖控件。 – 2010-07-19 01:56:40