1

I have about 2000 regions I want to monitor (entrance only) using CLLocationManager, I have a function that finds the 20 nearest stores (Store is a class that inherits from NSObject and has a CLLocationCoordinate2D property named geoPoint) to the user's current location but where should I call it?

If someone will be able to help me with a code example it'll be great!

Finding the 20 nearest stores func:

-(void)sortClosestStores
{
    [self.allStores sortUsingComparator:^NSComparisonResult(id  _Nonnull obj1, id  _Nonnull obj2) {
    CLLocation *location1=[[CLLocation alloc] initWithLatitude:((Store*)obj1).geoPoint.latitude longitude:((Store*)obj1).geoPoint.longitude];
    CLLocation *location2=[[CLLocation alloc] initWithLatitude:((Store*)obj2).geoPoint.latitude longitude:((Store*)obj2).geoPoint.longitude];

    float dist1 =[location1 distanceFromLocation:self.locationManager.location];
    float dist2 = [location2 distanceFromLocation:self.locationManager.location];
    if (dist1 == dist2) {
        return NSOrderedSame;
    }
    else if (dist1 < dist2) {
        return NSOrderedAscending;
    }
    else {
        return NSOrderedDescending;
    }
}];

    if (self.twentyClosestStores==nil) {
        self.twentyClosestStores=[NSMutableArray array];
    }

    if (self.previousTwentyStores==nil) {
        self.previousTwentyStores=[NSMutableArray array];
    }
    self.previousTwentyStores=self.twentyClosestStores;
    self.twentyClosestStores=[NSMutableArray array];

    for (int i = 0; i < 20; i++) {
        [self.twentyClosestStores addObject:[self.allStores objectAtIndex:i]];
    }
}

Thanks in advance!

FS.O
  • 403
  • 6
  • 24
  • You want to know when the device enters a store? – Black Frog Feb 01 '16 at 13:51
  • See [this question](http://stackoverflow.com/questions/29654154/need-to-get-more-than-20-notification-for-region-monitoring). There are other similar questions on SO that have more code too, but I couldn't find them immediately with a quick search. – Eric Galluzzo Feb 01 '16 at 14:01
  • @EricGalluzzo I've tried it but I couldn't understand, that's why I need a code here. – FS.O Feb 01 '16 at 14:06
  • What is significant location updates at all? And how is it different from the regular location updates. – FS.O Feb 01 '16 at 14:07

0 Answers0