Question

I am currently working on an app that will use the data returned by reversegeocode. Right now I can successfully receive the following values for a location: address, city, state, zip code, and country. In addition to the values that I am able to get, I would also like to obtain the name of the neighborhood for the locations that I reversegeocode. My code is as follows:

CLLocationManager *location = [[CLLocation alloc] init];
[location setDelegate:self];
location.desiredAccuracy=kCLLocationAccuracyBest;
location.distanceFilter=kCLDistanceFilterNone;

[location startMonitoringSignificantLocationChanges];

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

- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
{
NSLog(@"Update method is definitely being called!");
NSLog(@"Your current location is : %@", [locations lastObject]);
[geolocation reverseGeocodeLocation:[locations lastObject] completionHandler:^(NSArray *placemarks, NSError *error) {
    NSLog(@"Reverse geocode complete: %@", placemarks);

    CLPlacemark *placemark = [placemarks objectAtIndex:0];
    NSLog(@"The locality area is: %@", placemark.locality);
}];
}

I expected placemark.locality to return the neighborhood but it returns the city instead.

Any help would be greatly appreciated,
Dave

Was it helpful?

Solution

After reading the documentation Apple has for the CLPlacemark class, I noticed that there were a few fields that I was unaware of.

Inclusive in these fields is exactly what I was trying acquire, the subLocality, which seems to be Apple documentation for neighborhood. If I had just read the documentation instead of assuming the object returned from [placemarks objectAtIndex:0], when stored in CLPlacemark *placemark, would have no more data than what is shown when NSLog(@"%@", [placemarks objectAtIndex:0]) is called, I would have figured this out much sooner. Oh well. The code I used to access the neighborhood is:

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