iOS Geofencing未在目标c中调用didEnterRegion
,didExitRegion
和didStartMonitoringForRegion
。
我想实现一个单一的视图应用程序,我在可可豆荚中使用Google maps SDK。
我在info.plist中包含了相应的键,如此
<key>NSLocationAlwaysUsageDescription</key>
<string>Location is required for geofence</string>
<key>NSLocationWhenInUseUsageDescription</key>
<string>Location is required for geofence</string>
这是我的代码:
- (void)viewDidLoad {
[super viewDidLoad];
double Lat=22.569643;
double Lon=88.432058;
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:Lat longitude:Lon zoom:14];
_mapView = [GMSMapView mapWithFrame:CGRectZero camera:camera];
self.view=_mapView;
_mapView.myLocationEnabled = YES;
circ = [GMSCircle circleWithPosition:CLLocationCoordinate2DMake(Lat, Lon) radius:52];
circ.fillColor = [UIColor colorWithRed:0.25 green:0 blue:0 alpha:0.05];
circ.strokeColor = [UIColor redColor];
circ.strokeWidth = 1;
circ.map = _mapView;
CLCircularRegion *cir=[[CLCircularRegion alloc]initWithCenter:CLLocationCoordinate2DMake(Lat, Lon) radius:52 identifier:@"hi"];
locationManager = [CLLocationManager new];
[locationManager requestAlwaysAuthorization];
locationManager.delegate = self;
locationManager.distanceFilter = 10.0;
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
[locationManager startMonitoringForRegion:cir];
cir.notifyOnEntry = YES;
cir.notifyOnExit = YES;
[locationManager startUpdatingLocation];
}
答案 0 :(得分:0)
Apple说(在Location & Maps PG中)应假设区域的最小距离为200米。
特定阈值距离由当前可用的硬件和定位技术决定。例如,如果禁用Wi-Fi,则区域监控的准确性要低得多。但是,出于测试目的,您可以假设最小距离约为200米。
我也遇到了类似地理围栏的问题。将半径增加到100米时效果很好。如果要监视半径较小的区域,则应该监听位置更新,并检查该点周围区域是否存在该位置。