1

Actually, I'm trying to remove the deprecated code from my app (Modifying the target deployment from iOS6 to iOS7) and I'm looking for alternatives. Here is the old code:

- (void) mapTapped:(UITapGestureRecognizer *)sender
{
    CMELog(@"mapTapped");
    if (sender.state != UIGestureRecognizerStateEnded)
        return;

    CGPoint mapTouchPoint = [sender locationInView:mainMapView];
    CLLocationCoordinate2D mapTouchCoord = [mainMapView convertPoint:mapTouchPoint toCoordinateFromView:mainMapView];
    MKMapPoint touchMapPoint = MKMapPointForCoordinate(mapTouchCoord);
    CMELog(@"touchMapPoint: x:%f, y:%f", touchMapPoint.x, touchMapPoint.y);

    // this is where things can get inefficient if you have loads of overlayViews that aren't even visible!
    for (id<MKOverlay> overlay in self.mainMapView.overlays)
    {
        MKOverlayView *overlayView = [self.mainMapView viewForOverlay:overlay];
        CGSize overlayViewSize = overlayView.frame.size;
        CGPoint touchPoint = [sender locationInView:overlayView];
        // check to see if the point is within the overlay bounding box first
        if (touchPoint.x > 0 && touchPoint.x < overlayViewSize.width && touchPoint.y > 0 && touchPoint.y < overlayViewSize.height)
        {
        }
    }
}

I replaced the first line in the loop by the following:

MKOverlayRenderer *rendererOverlay = [self.mainMapView rendererForOverlay:overlay];

But I could not find how to get the frame of the render overlay. Any idea please?

Maystro
  • 2,907
  • 8
  • 36
  • 71
  • What was the purpose of the old code? Is sender a gesture recognizer? What view was it added to? What do you do with touchPoint? Related: http://stackoverflow.com/questions/20858108/detecting-touches-on-mkoverlay-in-ios7-mkoverlayrenderer –  Mar 21 '15 at 20:56
  • 1
    You want to know which overlay was touched, right? See the linked answer. You don't need the overlay's "frame". –  Mar 21 '15 at 22:31
  • Yep, you're right it worked. – Maystro Mar 22 '15 at 01:43

0 Answers0