Human readable location in iOS 6.1 - ios

Since the 6.1 update I can only reverse the first 25% of all the photos containing CLLocation information.
After the first 25% I get for all the others: Error Domain=kCLErrorDomain Code=2 "The operation couldn’t be completed. (kCLErrorDomain error 2.)".
I am processing all the images so maybe I am calling the service too often too quickly? But not limitation on this regard is mentioned anywhere :S
Code
CLLocation *location = [asset valueForProperty:ALAssetPropertyLocation];
if(location != nil){
CLGeocoder * geoCoder = [[CLGeocoder alloc] init];
[geoCoder reverseGeocodeLocation:location completionHandler:^(NSArray *placemarks, NSError *error)
{
if(placemarks.count == 0){
// this happens with more than 75% of the photos
return;
}
// this only happens with the other 25%
}];
}
Thanks!

I found this answer which says that there's a limitation of 50 requests per unknown amount of time.

Related

What is the replacement for getFromLocationName() for IOS?

I have implemented google map on IOS, now i want to locate marker on some company brand name, before i have experience of implementing in Android.
In Android getFromLocationName() to get the address info like lat, long from geocoder but I am not getting any in build function like this in IOS?
any help?
i think its giving you error because, geocoder is not able to find the location.
check this code ,
CLGeocoder *geocoder = [[CLGeocoder alloc] init];
[geocoder geocodeAddressString:#"Palolem Beach, Goa, India" completionHandler:^(NSArray* placemarks, NSError* error){
if (!error) {
for (CLPlacemark* aPlacemark in placemarks)
{
NSLog(#"place--%#", [aPlacemark locality]);
NSLog(#"lat--%f\nlong--%f",aPlacemark.location.coordinate.latitude,aPlacemark.location.coordinate.longitude);
}
}
else{
NSLog(#"error--%#",[error localizedDescription]);
}
}];

CLGeocoder reverseGeocodeLocation returning nil placemarks randomly

I am calling the following method, but randomly the placemarks NSArray is coming back nil. I have a break point set if location is nil and I have validated that the location is a valid object even when placemarks comes back nil. I can't figure out what is going wrong? Any suggestions?
-(void)geocodeRequest:(CLLocation *)location {
CLGeocoder
* gc = [[CLGeocoder alloc] init];
if(nil == location){
DLog(#"");
}
[gc reverseGeocodeLocation:(CLLocation *)(location) completionHandler:^(NSArray *placemarks, NSError *error) {
//Get address
CLPlacemark *placemark = [placemarks objectAtIndex:0]; <-- nil sometimes
.....
.....
}];
}// end geocodeRequest method
// UPDATE //
It is erroring out with!!!
Error Domain=kCLErrorDomain Code=2 "The operation couldn’t be completed. (kCLErrorDomain error 2.)"
The issue is this error which is Apple not returning a result as I have made to many requests to their API.
"Error Domain=kCLErrorDomain Code=2 "The operation couldn’t be completed. (kCLErrorDomain error 2.)"
I rewrote part of the app so it doesn't ask Apples API to reverse geocode so often. I have also hooked up to Googles API so if Apple returns this error I ask Google to do the reverse geocode.

When use ResreverseGeocodeLocation of CLGeocoder but the returned placemarks is nil and the kCLErrorDomain error =8

I want to get the location by the CLLocationCoordinate2D and I used the following code
//newLocation is a CLLocationCoordinate2D object
CLGeocoder *geocoder = [[CLGeocoder alloc] init];
[geocoder reverseGeocodeLocation:newLocation completionHandler:
^(NSArray *placemarks, NSError *error){
CLPlacemark *placemark = [placemarks objectAtIndex:0];
self.locationInput.text =placemark.subLocality;
self.locationInput.text =placemark.ISOcountryCode;
}];
but the returned placemarks is nil and the error description is kCLErrorDomain error =8
The return values are documented here.
https://developer.apple.com/library/ios/#documentation/CoreLocation/Reference/CoreLocationConstantsRef/Reference/reference.html#//apple_ref/doc/uid/TP40010237-CH2-SW2
Number 8 is "kCLErrorGeocodeFoundNoResult", so I suspect you're searching for something with no results. I've read elsewhere that CLGeocoder only runs on a device (not the simulator) but I haven't verified it myself. If you are sure your search string should get results, try your code on a device.
My issue was that I was using a VPN connected to a Thai server, trying to do a reverseGeocodeLocation on a UK postcode.
When I switched the VPN to a UK server it worked fine.

CLGeocoder reverseGeocodeLocation in China

I'm using CLGeocoder reverseGeocodeLocation to get addresses from coordinates, it seems that in China is returning "The geocoder has failed: Error Domain=kCLErrorDomain Code=8 "The operation couldn’t be completed. (kCLErrorDomain error 8.)" for loc : 50.820835 4.385551".
Has someone had issues with reverseGeocodeLocation in China starting from iOs 5.0?
kCLErrorDomain error 8 is kCLErrorGeocodeFoundNoResult.
I had similar issues in Romania, but,
the code below should return at least the city, if not the full address.
[_geoCoder reverseGeocodeLocation:location
completionHandler:
^(NSArray *placemarks, NSError *error) {
// Iterate trough placemarks
CLPlacemark *placemark = [placemarks objectAtIndex:i];
NSDictionary *addressDict = [placemark addressDictionary];
//addressDict should contain your info.
}];
Sometimes in China you can only reverse geocode locations in China.
China government has been blocking Google and its services for a long time. For residents in northern America, please do not expect to have access detailed geographical info of China. Both sides block each other.

CLGeocoder reverseGeocodeLocation returns 'kCLErrorDomain error 9'

I'm developing an iOS app with reverse geocoding features according to this article: geocoding tutorial
But when I test like this on simulator, I get 'kCLErrorDomain error 9'. I've searched a lot and there are only error 0 or 1 not 9.
Here is my code in viewDidLoad:
self.locationManager = [[CLLocationManager alloc]init];
self.locationManager.delegate = self;
self.locationManager.distanceFilter = 80.0;
[self.locationManager startUpdatingLocation];
CLGeocoder *geocoder = [[[CLGeocoder alloc] init] autorelease];
[geocoder reverseGeocodeLocation:self.locationManager.location
completionHandler:^(NSArray *placemarks, NSError *error) {
NSLog(#"reverseGeocodeLocation:completionHandler: Completion Handler called!");
if (error){
NSLog(#"Geocode failed with error: %#", error);
return;
}
if(placemarks && placemarks.count > 0)
{
//do something
CLPlacemark *topResult = [placemarks objectAtIndex:0];
NSString *addressTxt = [NSString stringWithFormat:#"%# %#,%# %#",
[topResult subThoroughfare],[topResult thoroughfare],
[topResult locality], [topResult administrativeArea]];
NSLog(#"%#",addressTxt);
}
}];
Thank you very much.
The Core Location error codes are documented here.
Code values 8, 9, and 10 are:
kCLErrorGeocodeFoundNoResult,
kCLErrorGeocodeFoundPartialResult,
kCLErrorGeocodeCanceled
Based on the code shown, the most likely reason you'd get error 8 is that it's trying to use location immediately after calling startUpdatingLocation at which time it might still be nil.
It usually takes a few seconds to obtain the current location and it will most likely be nil until then (resulting in geocode error 8 or kCLErrorGeocodeFoundNoResult). I'm not sure what error code 9 means by "FoundPartialResult" but Apple's GeocoderDemo sample app treats both the same way (as "No Result").
Try moving the geocoding code (all the code after the startUpdatingLocation call) to the delegate method locationManager:didUpdateToLocation:fromLocation:. The location manager will call that delegate method when it actually has a location and only then is it safe to use location.
There, after the geocoding is successful (or not), you may want to call stopUpdatingLocation otherwise it will try geocoding every time the user location is updated.
You may also want to check the accuracy (newLocation.horizontalAccuracy) and age (newLocation.timestamp) of the received location before trying to geocode it.
It turns out I mixed up the longitute and latitude when creating the location. Thought I'd add this as something for people to check.

Resources