CLPlacemark country property is null

- (void)GEOLocator

{

CLGeocoder *geocoder = [[CLGeocoder alloc] init];

CLLocation *myLocation = [[CLLocation alloc] initWithLatitude:currentCentre.latitude longitude:currentCentre.longitude];

[geocoder reverseGeocodeLocation:myLocation completionHandler: ^(NSArray *placemarks, NSError *error)

{

// the returned error code is 0

NSLog(@"%ld",(long)error.code);

// there’s only one entry in the placemarks NSArray

NSLog(@"placemarks count(%lu)",(unsigned long)[placemarks count]);

CLPlacemark *placemark = [placemarks firstObject];

// and the country property is null

NSLog(@"placemark.country(%@)",placemark.country);

}

];

}



currentCentre.latitude and currentCentre.longitude is hardcoded to downtown San Francisco: these have been proven to work.


the NSLog output’s are:


2015-08-29 15:47:48.299 WheresMyBeer[10128:548448] 0

2015-08-29 15:47:48.299 WheresMyBeer[10128:548448] placemarks count(1)

2015-08-29 15:47:48.300 WheresMyBeer[10128:548448] placemark.country((null))



can someone please explain how this is? the latest Xcode/iOS download no longer can tell me what country I’m in?!

Answered by chuckc192000 in 47141022

Are any of the other fields non-null?

Accepted Answer

Are any of the other fields non-null?

good catch. thanks! i should have looked at the other properties. yes, many of the other properties are also null and deeper investigation showed the Simulator had me out in the middle of the North Atlantic! the difficulty lie in setting a test lat/long value and the fact one can do that in multiple places: 1) Edit Scheme, 2) the Simulator Loction menu item, and 3) directly in source.


so, if these various settings conflict, what happens? it would be nice to set test lat/long's in one place and everything then just works.


thanks again.

You're welcome! I guess modifying the source to hard code a location would override anything else. I think setting the simulator location takes priority over the scheme setting -- the simulator can simulate a moving location. If the fixed location of the scheme took priority, the simulator moving location wouldn't work.

CLPlacemark country property is null
 
 
Q