John Dorsey
John Dorsey

Reputation: 157

Detect if a location is visible on rotating MkMapView

I am using an MkMapView with mkusertrackingmodefollowwithheading tracking mode so that the map rotates according to the compass heading.

I need to know if a particular location is visible on the mapview or not.

Considering that the mapview is rotating, this seems rather hard, but also like a common need for many different apps.

Is there any way to do it?

Thanks! -c

Upvotes: 1

Views: 410

Answers (1)

John Dorsey
John Dorsey

Reputation: 157

after several hours of research i seem to have found a solution....

// testing if someLocation is on rotating mapView
CGRect myRect = [self.mapView frame];
CGPoint screenP = [self.mapView convertCoordinate:someLocation toPointView:self.mapView];
if(screenP.x > 0) {
  if(screenP.y > 0) {
    if(screenP.x < myRect.size.width) {
      if(screenP.y < myRect.size.height) {
        return YES;
      }
    }
  }
}
return NO;

anyway,... this appears to work pretty well. -c

Upvotes: 2

Related Questions