6

Does anyone know any knowledge of using this:

- (void) startMonitoringForRegion:(CLRegion *)region desiredAccuracy:(CLLocationAccuracy)accuracy

I am trying to implement it into my project but:

- (void) locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region

is never being called?

Does anyone have any example code or know why this is happening?

My code is as follows. I created a method like this in my own LocationManager class:

 - (void) locationManagerStartMonitoringRegion:(CLRegion *)region withAccuracy:(CLLocationAccuracy)accuracy {
    NSLog(@"Start Monitoring");
    [locationManager startMonitoringForRegion:region desiredAccuracy:accuracy];
    NSLog(@"Monitored Regions: %i", [[locationManager monitoredRegions] count]);
}

I then call it like this:

CLLocationCoordinate2D coordinates = CLLocationCoordinate2DMake(51.116261, -0.853758);     
CLRegion *grRegion = [[CLRegion alloc] initCircularRegionWithCenter:coordinates radius:150 identifier:[NSString stringWithFormat:@"grRegion%i", value]];

[locationManager locationManagerStartMonitoringRegion:grRegion withAccuracy:kCLLocationAccuracyBest];

I get NSLog's of:

2011-01-30 19:52:26.409 TestingLocation[10858:307] Start Monitoring

2011-01-30 19:52:27.103 TestingLocation[10858:307] Monitored Regions:

But never get an NSLog from:

 - (void) locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region     {
    NSLog(@"Entered Region");
}

or

 - (void) locationManager:(CLLocationManager *)manager monitoringDidFailForRegion:(CLRegion *)region withError:(NSError *)error {
    NSLog(@"monitoringDidFailForRegion: %@",error);
}

Thanks

Community
  • 1
  • 1
jodm
  • 2,607
  • 3
  • 25
  • 40

5 Answers5

5

You'll need to move rather a long way for the region-monitoring stuff to work. Its current granularity seems to be based on when it gets handed off from one cell tower to another—in my testing, I had to move a mile or more for it to register that I had definitively left a small region I'd set.

Noah Witherspoon
  • 57,021
  • 16
  • 130
  • 131
  • 1
    This morning on the way to the office i registered about 5 points on the way and 3 of them triggered. This is defiantly the case. didEnterRegion is only called when changing cell tower OR there is a significant change of location. This does not help with the context I wanted to use region monitoring :( – jodm Jan 31 '11 at 08:26
  • @jodm, I know this was from over a year ago but have things gotten better? I have the same trouble where I had points that wouldn't trigger or that would trigger very late. There's has to be a better way.. – ari gold Sep 15 '12 at 17:47
  • I can confirm that region monitoring uses Significant location to some capacity, I disassembled the framework binary and found stuff related to calls to significant location. But even still, that's inconclusive. – Nate Symer Jul 20 '13 at 23:37
1

The Answer is :

- (void) startMonitoringForRegion:(CLRegion *)region desiredAccuracy:(CLLocationAccuracy)accuracy

is deprecated in ios 6.o. Instead use `- (void) startMonitoringForRegion:(CLRegion *)region.

Thanks, Abdul`

Abdul Yasin
  • 3,480
  • 1
  • 28
  • 42
  • https://developer.apple.com/library/ios/documentation/CoreLocation/Reference/CLLocationManager_Class/index.html#//apple_ref/occ/instm/CLLocationManager/startMonitoringForRegion:desiredAccuracy: – mcphersonjr Jan 21 '15 at 21:56
1

Well you can monitor multiple regions and simulate location in Xcode (from the panel above the debugger) to check whether it's working or not. I've tested and it works pretty smooth.

Gautam Jain
  • 2,913
  • 30
  • 25
1

The Accuracy is improved in ios 5.

Andrew Thomas
  • 2,482
  • 3
  • 25
  • 29
  • Do you have a sense of what was fixed? I'm still having trouble in the Eugene Oregon (~150,000 people) which leads me to believe that it's based upon cell towers and WiFi. Of course that'd be crazy if that's the case as it would make **region monitoring** only useful in dense urban areas. – ari gold Sep 18 '12 at 18:51
  • It does work in ios 5 and 6 based on cell towers and wifi. It does work best in dense urban areas. The only places I have complaints about my app are in very desolate areas (an island, northern canada). – Andrew Thomas Sep 18 '12 at 19:04
0

I'd have to see where you setup your locationManager instance. But as @Mark Adams is trying to elude to, you need to set your current class as the delegate for locationManager so it knows which class to send messages back to. It is as simple as:

locationManager.delegate = self;

raidfive
  • 6,603
  • 1
  • 35
  • 32