iosswiftmapkitmkpinannotationview

How To Detect A User Is Within Range Of An Annotation


So I am working on a project that includes many uses placing annotations all around a map. The annotation, (which is a custom image with a much larger circular range) appears on the screen and, ideally, I would like for a user to be:

  1. Notified if they are within the range of a annotation and
  2. Not be allowed to place another annotation within the range of another one if the circular pins overlap by, say, more than 25%

I think this is a pretty unique question and should be fun for somebody to help out with, so have fun! Thanks everybody!


Solution

  • You can check the distance from each annotation using

    - (CLLocationDistance)distanceFromLocation:(const CLLocation *)location
    

    This method measures the distance between the two locations by tracing a line between them that follows the curvature of the Earth. The resulting arc is a smooth curve and does not take into account specific altitude changes between the two locations.

    For more details refer Link