Search code examples
iphonelatitude-longitudecllocation

CLLocation - add 2km or 2000m radius to a coordinate


How can I add a radius to a CLLocation coordinate? What I want is to see what clients are near a specific coordinate.

What I need is to add 2000 meters, or 2km to a coordinate.

How do I do that?


Solution

  • You can't "add a radius" to a coordinate. What you can do if you have CLLocation objects (say loc1 and loc2), is calculate the distance between them:

    CLLocationDistance dist = [loc1 distanceFromLocation:loc2];
    

    and see if dist (which is in meters) is more or less than 2000.0.

    Converting between coordinate latitudes/longitudes (which are polar coordinates) and distances is complicated, which is why the SDK provides you with this functionality.