Search code examples
iosmkmapviewmkoverlay

Check if MKPolyline intersects MKPolygon


I'm trying to figure out if a MKPolyline intersects an MKPolygon on map. Currently the only idea I have about this is to go through the line and test on every point if it is located in polygon. More exactly, I'm trying to test if there aren't any MKPolygon between MKUserLocation and an objective on map (so MKUserLocation can see that objective).

Any more practical idea about how to do this? If not, how to transform the MKPolyLine into a lot of points?


Solution

  • They both conform to the MKOverlay protocol. You can use the property defined on the protocol called boundingMapRect, and use it on a protocol-defined method called intersectsMapRect. More info here:

    http://developer.apple.com/library/ios/#DOCUMENTATION/MapKit/Reference/MKOverlay_protocol/Reference/Reference.html