Friday, November 6, 2026
HomeiOS Developmentios - SwiftUI MapKit test overlay intersection (MKPolygon || MKCircle)

ios – SwiftUI MapKit test overlay intersection (MKPolygon || MKCircle)

[ad_1]

I’m attempting to detect wether two MKOverlays (is likely to be circles or polygons) intersect.

Tried utilizing boundingMapRect nevertheless it attracts a rectangle round my overlay thus giving me inaccurate outcomes.

if polygon != nil {
            intersectionOverlay = polygon!
        } else {
            intersectionOverlay = circle!
        }
for overlay: MKOverlay in mapView.overlays {
            let rect = overlay.boundingMapRect
            if rect.intersects(intersectionOverlay.boundingMapRect) { 
            print("Intersects (overlay.title)")
}

Utilizing that piece of code, would return true for the state of affairs within the pictures under. Is there some other higher method to obtain the specified outcomes? Thanks

enter image description here

enter image description here

[ad_2]

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments