Search code examples
objective-ciosclgeocoder

CLGeocoder returning locations in other countries


I have the following code:

CLGeocoder *_geo = [[CLGeocoder alloc] init];
CLRegion *region = [[CLRegion alloc] initCircularRegionWithCenter: CLLocationCoordinate2DMake(37.33233141, -122.03121860) radius:100 identifier:@"San Francisco"];
[_geo geocodeAddressString:@"Starbucks" inRegion:region
             completionHandler:^(NSArray *placemarks, NSError *error)
{
    NSLog("%@", placemarks);
}];

This returns a Starbucks location in the Philippines even though the center is in the middle of San Francisco.

(NSArray *) $3 = 0x07cd9d10 <__NSArrayM 0x7cd9d10>(
Starbuck's, Metro Manila, Quezon City, Republic of the Philippines @ <+14.63617752,+121.03067530> +/- 100.00m, region (identifier <+14.63584900,+121.02951050> radius 166.35) <+14.63584900,+121.02951050> radius 166.35m
)

Any ideas?


Solution

  • Though it seems unlikely, it certainly appears that either a) Apple didn't intend on forward geocoding business names near a region, or b) this is a bug.

    The CLGeocoder reference, in its overview, states:

    Forward-geocoding requests take a user-readable address and find the corresponding latitude and longitude value...

    which certainly implies a real physical address as the search string (especially the "user-readable address" part). However, the docs for geocodeAddressString: inRegion: completionHandler: states that the search string is:

    ... a string describing the location you want to look up...

    which is even more vague. I tried running your code, and code very similar to it, through a couple of my projects and I get the same result. Even Apple's GeocoderDemo sample exhibits the problem (although I live in California just ~150 miles from your lat/long example), so it's certainly nothing either of us have written.

    I set out looking to help solve this problem for/with you! But, this bit of is research is all I've got. Best of luck.