Let*_*Ask 3 c# geolocation geo latitude-longitude
我需要在C#中实现Geofence.地理围栏区域可以是圆形,矩形,多边形等.有没有人在C#中实现Geofence?
我发现了Geo Fencing - 指向内/外多边形.但是,它仅支持多边形.
我测试了各种实现,这个例子适合我:
public static bool PolyContainsPoint(List<Point> points, Point p) {
bool inside = false;
// An imaginary closing segment is implied,
// so begin testing with that.
Point v1 = points[points.Count - 1];
foreach (Point v0 in points)
{
double d1 = (p.Y - v0.Y) * (v1.X - v0.X);
double d2 = (p.X - v0.X) * (v1.Y - v0.Y);
if (p.Y < v1.Y)
{
// V1 below ray
if (v0.Y <= p.Y)
{
// V0 on or above ray
// Perform intersection test
if (d1 > d2)
{
inside = !inside; // Toggle state
}
}
}
else if (p.Y < v0.Y)
{
// V1 is on or above ray, V0 is below ray
// Perform intersection test
if (d1 < d2)
{
inside = !inside; // Toggle state
}
}
v1 = v0; //Store previous endpoint as next startpoint
}
return inside;
}
Run Code Online (Sandbox Code Playgroud)