Question

I want to detect when the user has travelled to a new country and so am intending to use startMonitoringSignificantLocationChanges: in combination with reverseGeocodeLocation:.

However I was wondering what to do if reverseGeocodeLocation: returns more than one placemark. As the level of granularity I need is just down to the country level could I just pick any of the place marks as they will all presumably be for the same country?

Was it helpful?

Solution

The placemarks contain a location property which will let you see which one is physically closest to your technical current location. So you could loop thru and find the one that is closest, then use that one. But they should all be extremely close geographically to the location used to do the lookup, so they would almost certainly all be for the same country, unless maybe you were standing on the border.

The likelihood that this even matters, however, is extremely slim. You should just pick an element, either the first or the last, from the array. Go ahead and use it as if it's the only one, because really it doesn't matter if more than one are present. Most code that you'll find will include a check to see if there's at least one, and then grab the first or last placemark to use.

OTHER TIPS

From CLGeocoder Class Reference

typedef void (^CLGeocodeCompletionHandler)(NSArray *placemark, NSError *error);

Contains an array of CLPlacemark objects. For most geocoding requests, this array should contain only one entry. However, forward-geocoding requests may return multiple placemark objects in situations where the specified address could not be resolved to a single location.

In your case, when you are only interested in a country, you should not be bothered by which placemark to choose. Just take the first one.

[placemark firstObject];
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top