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.
Related
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.
At the moment I'm working on an application for the iPad, which at a certain point should show a list of cities with next to these cities the distance from the users current location.
I'm using a loop which uses a database I built earlier. This is the code:
NSString *address = [NSString stringWithFormat:#"%#, Nederland", [info2 objectForKey:#"stadsnaam"]];
[self.geocoder geocodeAddressString:address completionHandler:^(NSArray *placemarks, NSError *error) {
CLPlacemark *placemark = [placemarks objectAtIndex:0];
CLLocation *location = placemark.location;
CLLocationCoordinate2D firstLocation = location.coordinate;
NSLog(#"%f,%f", firstLocation.latitude, firstLocation.longitude);
}];
This piece of code is inside a for loop. But the first time it is run, it just returns 0.0000
The second time the loop is activated (and I'm sure it runs more than one time) it returns only the distance between the current location and the FIRST city.
The app gets the city names from this piece of code:[NSString stringWithFormat:#"%#, Nederland", [info2 objectForKey:#"stadsnaam"]]
Which I verified and works. I would like to avoid using the Google API because I will be making more than the maximum request a day probably XD
Any help is appreciated, please inform me if anything isn't completely clear and thanks in advance!
You need to read the documentation for -geocodeAddressString:completionHandler::
After initiating a forward-geocoding request, do not attempt to initiate another forward- or reverse-geocoding request.
You can use CLGeocoder's geocoding property to determine whether a geocoding operation is in progress.
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.
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.
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.