0

I am Developing an App which is based on MKMapView, and the requirement of the App is to detect whether the userLocation (represented by Blue dot) is lying on the visible area of the screen or it is outside the visible Screen Area.

In the beginning when map gets loaded, it automatically set it's position to the user's location but I want to detect wether current location is in the visible area of screen or not, after user scroll the map view.

Please provide useful solutions and help me out.

Thanks in advance.

Mayur Prajapati
  • 5,454
  • 7
  • 41
  • 70
Tarun9573
  • 1
  • 3
  • possible duplicate of [Check if user location is visible on map iphone](http://stackoverflow.com/questions/7320101/check-if-user-location-is-visible-on-map-iphone) – Volker Mar 28 '14 at 08:44

1 Answers1

1

just use userLocationVisible ( I didnt remember but @Volker reminded me)


any annotation:

get the location and check if the pixel coordinate is visible

  1. get the userLocation from the map
  2. get its coordinate
  3. convert it to a mappoint (MKMapPointForCoordinate)
  4. get the mapview's visible mapRect
  5. use MKMapRectContainsPoint

    MKMapRect visibleRect = self.mapView.visibleMapRect;
    MKMapPoint pt = MKMapPointForCoordinate(self.mapview.userLocation.coordinate);
    
    BOOL visible = MKMapRectContainsPoint(visibleRect, pt);
    
Daij-Djan
  • 49,552
  • 17
  • 113
  • 135
  • why not just use `userLocationVisible` ? – Volker Mar 28 '14 at 08:46
  • @Volker :D because I didnt remember that – Daij-Djan Mar 28 '14 at 08:49
  • and here is the answer to my own question: - (void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated { if (!mapView.userLocationVisible) NSLog(@"userlocation is not visible"); else NSLog(@"user location is visible now"); } – Tarun9573 Mar 28 '14 at 09:03
  • and Thankyou Volker and Daij-Djan for you answer, that helped me a exactly what i want to achieve. – Tarun9573 Mar 28 '14 at 09:06