1
votes

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

1
Can you name an example when this would be needed? I would think most case are covered by putting an annotation on the map and letting the mapview draw it if it is on screen. - Craig
example: you want to see the location of the stores where you have an errand to do. If you are facing north with a task/store just 0.5 km to east, you might not see it even though you can see another friend who is farther away but happens to fit on the screen at this moment. - John Dorsey
after you decide which stores you want to visit, you would like to see these all on the map while you go about. If the zoom is set to guarantee that all tasks are always visible regardless of compass heading, then the map must be zoomed out very far (much too far). isn't it better for the map to zoom in or out according to the compass heading and just know if all tasks are fitting or not? - John Dorsey
If you just want to zoom out far enough to ensure the closest pin is visible even if it is to the side, get the distance to the closest pin and set it as the half longitude span. - Craig
i might be wrong but i dont think that such a rule gives a good experience. i think the compass heading should be considered when deciding how far to zoom out. otherwise half of the map area is being wasted. here id an example: link - John Dorsey

1 Answers

2
votes

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