Question

I'm investigating the use of region monitoring for my app. Basically, I want to define a circle area and if the user is outside this circle, then the app won't work.

As I understand it, region monitoring only checks to see if the user crosses the boundary.

If this is the case, can somebody point me in the direction of a tutorial/blogpost which can help me achieve my goal?

Was it helpful?

Solution

Region Monitoring active on both if user comes in the boundary and goes out from boundary

Following methods are useful to check user comes in or goes out from particular defined boundary area :

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

NSLog(@"User Enters in Region");

}

-(void)locationManager:(CLLocationManager *)manager didExitRegion:(CLRegion *)region {

NSLog(@"User Goes out from Region");

}

OTHER TIPS

calculate the distance from current location to center of circle.
If distance > radius then outside.

You can use regions for monitoring user's in/out activity but normally you could register for Significant Location Change and then check whether user's location is in some limited distance from the point. You can easily calculate distance between two CLLocation points by calling on one sth like this:

[myLoc distanceFromLocation:locationOfCenterOfCircle] 

and compare it with radius. Method above returns result in meters. In this case worth reading will be this especially about Significant Location Change.

You can perform a requestStateForRegion:(CLRegion *) on the CLLocationManager.

This way the delegate class' delegate method : -(void) locationManager:(CLLocationManager *)manager didDetermineState:(CLRegionState)state forRegion:(CLRegion *)region will be fired.

In there you can check if you're inside the region or outside. So basically if you request the state somewhere near the beginning of your app, you can determine whether the user is in or outside your fence.

That'd make something like :

-(void) locationManager:(CLLocationManager *)manager didDetermineState:(CLRegionState)state forRegion:(CLRegion *)region{
if (state == CLRegionStateInside){
    // Inside geofence
} else {
    // Keep state disabled
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top