Since CLLocationCoordinate2D
is a struct, you can compare the coordinate
@properties of two MKAnnotation
s with ==
. Example:
MKAnnotation *a1;
MKAnnotation *a2;
if(a1.coordinate == a2.coordinate) {
//coordinates equal
}
With the caveat: you care comparing floating point values in the CLLocationCoordinate2D
(the latitude and longitude fields of CLLocationCoordinate2D
are of type CLLocation
which is typdef
ed as double
). As always, comparing two floating point values for equality is fraught with subtlety. You may want to do a more involved comparison of the latitude and longitude values independently (e.g. checking wither their absolute difference is within some small range). See Numerical Recipes for more info on this issue.
If you want to compare all properties, something like
(a1.coordinate == a2.coordinate) && [a1.title isEqualToString:a2.title] && [a1.subtitle isEqualToString:a2.subtitle]
(again with the save caveat) would do the trick.