我目前正试图让我的应用程序监控特定区域使用CoreLocation但是我发现它似乎没有按预期工作,在我看来,它不能用于每个位置的小半径设置,即10米.
我还整理了一个小测试应用程序,在地图上绘制圆形半径,以便我可以直观地看到发生了什么.
我用于监控位置的代码如下:
self.locationManager = [[CLLocationManager alloc] init];
self.locationManager.delegate = self;
self.locationManager.desiredAccuracy = kCLLocationAccuracyBest;
// Set-up a region
CLLocationDegrees latitude = 52.64915;
CLLocationDegrees longitude = -1.1506367;
CLLocationCoordinate2D centerCoordinate = CLLocationCoordinate2DMake(latitude, longitude);
CLCircularRegion *region = [[CLCircularRegion alloc] initWithCenter:centerCoordinate
radius:10 // Metres
identifier:@"testLocation"];
[self.locationManager startMonitoringForRegion:region];
Run Code Online (Sandbox Code Playgroud)
我没有在这里为DidEnter区域等提出代码,因为我知道当我离监控区域超过100米时可以工作.
这是应用程序的屏幕截图,当我距离地图上的紫色位置超过10米时,确实的出口区域事件不会触发,但是如果我将我的位置切换到伦敦则会触发它以及当我设置我的位置时回到目前蓝色位置的地方它也会发射.

有没有人知道最小区域半径是否有限制,或者我做错了什么.
谢谢亚伦
core-location cllocationmanager ios geofencing clcircleregion
我正在尝试测试区域监控,因为我正在获得这样的当前位置:
- (void)startLocationTracking
{
CLLocationManager *locationManager = [[CLLocationManager alloc] init];
// Start location manager
if ([CLLocationManager locationServicesEnabled] && [CLLocationManager authorizationStatus] == kCLAuthorizationStatusAuthorized) {
locationManager = [LocationTracker sharedLocationManager];
locationManager.delegate = self;
[locationManager startMonitoringSignificantLocationChanges];
}
}
Run Code Online (Sandbox Code Playgroud)
并跟踪区域监控的第一个位置,如下所示:
-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
{
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
CLRegion *region = [[CLRegion alloc] initCircularRegionWithCenter:manager.location.coordinate radius:300 identifier:@"first location initializer"];
NSLog(@"0: %@", manager.location);
NSLog(@"1: %@", region);
[manager startMonitoringForRegion:region];
NSLog(@"[locationManager startMonitoringForRegion:%@];", region);
});
}
Run Code Online (Sandbox Code Playgroud)
然后在当前区域的每个出口处,我正在监视新位置,如下所示:
- (void)locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region
{
NSLog(@"%s, %@", __PRETTY_FUNCTION__, region);
} …Run Code Online (Sandbox Code Playgroud)