该区域监视器的准确性非常差。任何人都可以解决这个问题?我的源代码的存储库在这里:https ://github.com/robert-yi-jones/RegionTrigger
我创建了一个 CLLocationCoordinate2D 变量,它是地图的中心。然后,我根据坐标设置了一个半径为 100 米的区域。
CLLocationCoordinate2D *targetPoint =
[[CLLocation alloc] initWithLatitude:MapView.centerCoordinate.latitude
longitude:MapView.centerCoordinate.longitude];
targetRegion = [[CLCircularRegion alloc] initWithCenter:targetPoint.coordinate
radius:300
identifier:@"My Circle Region"];
[locationManager startMonitoringForRegion:targetRegion];
但是,我开始监视的区域似乎运行不正常。
/*
* locationManager:didEnterRegion:
*
* Discussion:
* Invoked when the user enters a monitored region. This callback will be invoked for every allocated
* CLLocationManager instance with a non-nil delegate that implements this method.
*/
- (void)locationManager:(CLLocationManager *)manager
didEnterRegion:(CLRegion *)region{
if ([region.identifier isEqualToString:@"My Circle Region"]) {
[self showAlertWithTitle:@"Entering a Region"
Message:region.identifier];
}
}
/*
* locationManager:didExitRegion:
*
* Discussion:
* Invoked when the user exits a monitored region. This callback will be invoked for every allocated
* CLLocationManager instance with a non-nil delegate that implements this method.
*/
- (void)locationManager:(CLLocationManager *)manager
didExitRegion:(CLRegion *)region{
if ([region.identifier isEqualToString:@"My Circle Region"]) {
[self showAlertWithTitle:@"Exiting a Region"
Message:region.identifier];
}
}
只有当坐标切换到距离我的设置区域 6 公里左右的某个地方时,它才会注意到我。
有人有区域监视器示例代码吗?我真的找不到我的错误!