Core Location region monitoring
Asked Answered
S

5

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

Silverts answered 30/1, 2011 at 20:11 Comment(4)
Could you post the code you are using? It's hard to help without context.Clayberg
Code now added to original post above.Silverts
Have you set your LocationManager class as the delegate of CLLocationManager?Essence
@Silverts still facing this problem. did u get a solution for this. are you able to trigger didEnterRegion. kindly help with a working exampleChidester
U
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.

Unweave answered 31/1, 2011 at 1:30 Comment(3)
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 :(Silverts
@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..Instruction
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.Unprecedented
K
1

The Accuracy is improved in ios 5.

Kindred answered 13/9, 2011 at 6:23 Comment(2)
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.Instruction
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).Kindred
S
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`

Surge answered 15/7, 2013 at 5:49 Comment(1)
I
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.

Inexperienced answered 11/3, 2015 at 7:12 Comment(0)
T
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;

Trilbi answered 31/1, 2011 at 1:36 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.