-1

I have a location called savedLocation that contains a location that I've pre-saved to my app.

I want to check if the savedLocation and the user's current location are in the same city.

Creating the CLCircularRegion (saveLocation):

-(CLCircularRegion*)createCircularRegion
{
    CLCircularRegion *region=[[CLCircularRegion alloc] initWithCenter:self.geoPoint radius:200 identifier:self.identifier];

    region.notifyOnEntry=YES;

    return region;
}

Note: this question is different from this question because in this question I ask how to compare 2 different location's city (without getting nil), the "duplicate" question is about a different thing.

Anyone have an idea how can I do that?

Thank you very much!

Community
  • 1
  • 1
FS.O
  • 403
  • 6
  • 24

1 Answers1

0

You can use a Reverse Geocoder to get the city name of your location. Then compare it with the city name of your reference location. I think this might be inaccurate.

- (void)getCityNameFromLocation:(CLLocation *)location
{
    CLGeocoder *geocoder = [[CLGeocoder alloc] init] ;
    [geocoder reverseGeocodeLocation:location completionHandler:^(NSArray<CLPlacemark *> * _Nullable placemarks, NSError * _Nullable error) {
        if (error) {
            // Handle the error here
            return;
        }
        CLPlacemark *placemark = [placemarks objectAtIndex:0];
        NSLog(@"%@", placemark.locality);
    }];
}
audience
  • 2,412
  • 21
  • 18
  • That's what I thought to do but `reverseGeocodeLocation: completionHandler :` is running in a background thread (and I need to do it twice because I need to compare 2 locations) so when it gets to the `if` statement the `NSString` object (2 object - one for each city) is still `nil`, how can I handle it? – FS.O Feb 18 '16 at 13:08
  • @audience I wrote the same thing in http://stackoverflow.com/questions/35434026/gmsgeocoder-reversegeocodecoordinate-completionhandler-on-background-thread/35434233#35434233. This qs is a duplicate by the same author – Daij-Djan Feb 18 '16 at 13:12
  • @Daij-Djan Thanks! So I won't look into it any further. – audience Feb 18 '16 at 13:14
  • @audience I was saying the OP is cross posting, your answer is sound id say – Daij-Djan Feb 18 '16 at 13:15
  • @Daij-Djan I've updated this post with an exlenation why this post it different from the question you posted, I'll appriciate if you'll remove the "duplicate" mark from this question, thanks :) – FS.O Feb 18 '16 at 13:15
  • no. you don't explain why it is different at all which you can ALSO see by the way you got identical answers :) – Daij-Djan Feb 18 '16 at 13:17
  • "I ask how to compare 2 different location's city (without getting nil), the "duplicate" question is about a different thing." ??? sounds quite same. and using GPS is async :) – Daij-Djan Feb 18 '16 at 13:19