I add a MKCircle
overlay to my mapview
and I want to know if a point (tap in screen) is inside the circle. This is my code :
- (BOOL)pointInsideOverlay:(CLLocationCoordinate2D )tapPoint overlay:(id<MKOverlay>)overlay {
BOOL isInside = FALSE;
MKPolygonView *polygonView = (MKPolygonView *)[self.mapView viewForOverlay:overlay];
MKMapPoint mapPoint = MKMapPointForCoordinate(tapPoint);
CGPoint polygonViewPoint = [polygonView pointForMapPoint:mapPoint];
BOOL mapCoordinateIsInPolygon = CGPathContainsPoint(polygonView.path, NULL, polygonViewPoint, NO);
if (mapCoordinateIsInPolygon) {
isInside = TRUE;
}
return isInside;
}
viewForOverlay
, pointForMapPoint
& path
are deprecated. Is this the problem?
Thank you.
This apporach should work too, using MKCircleRenderer
:
MKCircleRenderer *circleRenderer = (MKCircleRenderer *)[mapview rendererForOverlay:circleOverlay];
[circleRenderer invalidatePath];
MKMapPoint mapPoint = MKMapPointForCoordinate(tapPoint);
CGPoint circlePoint = [circleRenderer pointForMapPoint:mapPoint];
BOOL mapCoordinateIsInCircle = CGPathContainsPoint(circleRenderer.path, NULL, circlePoint, NO);
if ( mapCoordinateIsInCircle )
{
//do something
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With