Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Core Location region monitoring

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

like image 898
jodm Avatar asked Jan 30 '11 20:01

jodm


People also ask

What is a core location?

Core Location provides services that determine a device's geographic location, altitude, and orientation, or its position relative to a nearby iBeacon device. The framework gathers data using all available components on the device, including the Wi-Fi, GPS, Bluetooth, magnetometer, barometer, and cellular hardware.

What is region tracking on iPhone?

Use region monitoring to determine when the user enters or leaves a geographic region.

What is Cllocationmanagerdelegate?

The methods that you use to receive events from an associated location-manager object. iOS 2.0+ iPadOS 2.0+ macOS 10.6+ Mac Catalyst 13.0+ tvOS 9.0+ watchOS 2.0+

Does iPhone have geofencing?

Setting up geofencing on an iPhone (iOS) Turn on Geofencing in the Home Center app (Application Settings > Geofencing). Go to the iPhone's Settings, scroll down and choose Home Center from the list. Tap Location and set Always (and make sure you have Precise Location enabled). Done.


2 Answers

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.

like image 200
Noah Witherspoon Avatar answered Sep 22 '22 02:09

Noah Witherspoon


The Accuracy is improved in ios 5.

like image 20
Andrew Thomas Avatar answered Sep 21 '22 02:09

Andrew Thomas