7

I'm trying to use (forward) geocoding using the new CLLocationManager APIs in iOS 5, and am not having any luck.

I am specifying a region based on the current location, and yet it's giving me results on the other side of the world.

//CLLocation *currentloc is set to the current location when I get in here (<+37.78583400,-122.40641700>)
CLRegion *region = [[CLRegion alloc] initCircularRegionWithCenter:[currentloc coordinate] radius:5000 /*meters*/ identifier:@"You are here"];
// Region is now: (identifier You are here) <+37.78583400,-122.40641700> radius 5000.00m

NSString *addressString = @"Citibank"; //for example
[geoCoder geocodeAddressString:addressString inRegion:region completionHandler:^(NSArray* placemarks, NSError* error){
    for (CLPlacemark* aPlacemark in placemarks)
    {                    // Process the placemark.
        NSLog(@"Got Placemark : %@", aPlacemark);     

    }
}];

And all I get is:

> 2011-12-14 15:50:49.882 [12377:12503] Got Placemark : Citibank, New
> Delhi, Delhi, India @ <+28.63470640,+77.22010140> +/- 100.00m, region
> (identifier <+28.63517750,+77.21878050> radius 154.35)
> <+28.63517750,+77.21878050> radius 154.35m
> 
> 2011-12-14 15:50:49.883[12377:12503] Got Placemark : CitiBank, Noida,
> Uttar Pradesh, India @ <+28.58157180,+77.32408380> +/- 100.00m, region
> (identifier <+28.58161950,+77.32315050> radius 154.41)
> <+28.58161950,+77.32315050> radius 154.41m
> 
> 2011-12-14 15:50:49.885 [12377:12503] Got Placemark : Citibank, New
> Delhi, Delhi, India @ <+28.53627320,+77.21128390> +/- 100.00m, region
> (identifier <+28.53630050,+77.21054050> radius 154.46)
> <+28.53630050,+77.21054050> radius 154.46m
> 
> ...

Any ideas:

  1. Does it think I'm in New Delhi? (I think the answer is no - because a search for "All Star Donuts" with the same inRegion puts me in Thailand

  2. Am I misusing "inRegion"

  3. Does this work for anyone? Because it will be GREAT if and when it does

Vineesh TP
  • 7,755
  • 12
  • 66
  • 130
snarshad
  • 469
  • 5
  • 9
  • I found a workaround to this issue by using the method `geocodeAddressString: completionHandler:` instead. Take a look at [my solution](http://stackoverflow.com/questions/10202550/clgeocoder-returning-locations-in-other-countries/13632049#13632049) to a very similar question. – msoler Oct 12 '15 at 17:12

1 Answers1

0

Ok, answers.

  1. No, it doesn't. It just uses region as place to search in first. From API:

    Specifying a region lets you prioritize the returned set of results to locations that are close to some specific geographical area, which is typically the user’s current location.

  2. All is ok.

  3. For request "starbucks" it returns me

    Got Placemark : Starbuck Dr, Sausalito CA 94965, United States @ <+37.86315000,-122.57986000> +/- 100.00m, region (identifier <+37.86315000,-122.57986000> radius 282.92) <+37.86315000,-122.57986000> radius 282.92m

so seems like it works.

My suggestion is to check distance between your region's center and center of placemark, returned from server.

Nikita Ivaniushchenko
  • 1,425
  • 11
  • 11
  • Thanks - good to know it works correctly for you; I could not get any better results and moved to using the Google places API instead (finally got that to work). Any chance you can try "Citibank" instead of Starbucks and see if you get one in Sausalito (and not New Delhi?) – snarshad Dec 22 '11 at 00:32