How do I test the equality of two CLLocations

Viewed 6966

I'm having a problem with isEqual:

The code:

 if (currentAnchor isEqual:currentBusiness.getCllLocation))
    {
        do a;
    }
    else
    {
        do b;
    }

currentanchor and currentbusiness.getCllocation are locations

But if they are the same, why is function b called? Is something wrong with my code?

4 Answers

Swift 4.0 version:

let distanceThreshold = 2.0 // meters
if location.distance(from: CLLocation.init(latitude: annotation.coordinate.latitude,
                                           longitude: annotation.coordinate.longitude)) < distanceThreshold
{ 
    // do a
} else {
    // do b
}
Related