判断地图坐标 是否在区域内


-(IBAction)foundTap:(UITapGestureRecognizer *)recognizer { CGPoint point = [recognizer locationInView:self.mapView]; CLLocationCoordinate2D tapPoint = [self.mapView convertPoint:point toCoordinateFromView:self.view]; [self pointInsideOverlay:tapPoint]; if (isInside) { .... } } 

Here is a method to call from the previous to check if the point is inside the overlay:

-(void)pointInsideOverlay:(CLLocationCoordinate2D )tapPoint { isInside = FALSE; MKPolygonView *polygonView = (MKPolygonView *)[mapView viewForOverlay:polygonOverlay]; MKMapPoint mapPoint = MKMapPointForCoordinate(tapPoint); CGPoint polygonViewPoint = [polygonView pointForMapPoint:mapPoint]; BOOL mapCoordinateIsInPolygon = CGPathContainsPoint(polygonView.path, NULL, polygonViewPoint, NO); if ( !mapCoordinateIsInPolygon ) //we are finding points that are inside the overlay { isInside = TRUE; } }

你可能感兴趣的:(地图)