MKPolygon - How to determine if a CLLocationCoordinate2D is in a CLLocationCoordinate2D polygon?

前端 未结 5 1003
春和景丽
春和景丽 2021-01-15 06:06

I have the swift code below that draws a polygon and drops an annotation on MKMapView. I am trying to figure out how i could identify if the annotation\'s coordinate is with

5条回答
  •  难免孤独
    2021-01-15 06:53

    How about using MkPolygon.intersect()? This requires converting the point to a tiny MKMapRect, but it is simpler and may get some acceleration from the underlying API:

    func pointIsInside(point: MKMapPoint, polygon: MKPolygon) -> Bool {
        let mapRect = MKMapRectMake(point.x, point.y, 0.0001, 0.0001)
        return polygon.intersects(mapRect)
    }
    

提交回复
热议问题