ユーザーがランドマークを訪問したかどうかを監視するために監視領域を使用しようとしています。 は、ロケーションマネージャは、ビューコントローラのviewDidLoadでmapkitiphone CLLocationmanagerリージョン監視コールバックがトリガーされない
と一緒のViewControllerに初期化される:
if (self.locationManager == nil)
{
// NSLog(@"creating location manager");
self.locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
locationManager.desiredAccuracy = kCLLocationAccuracyBestForNavigation;
locationManager.distanceFilter = kCLDistanceFilterNone;
}
NSSet* set=[locationManager monitoredRegions];
if ([CLLocationManager regionMonitoringAvailable] && [CLLocationManager regionMonitoringEnabled]) {
NSLog(@"region monitoring okay");
NSLog(@"monitored regions: %@",set);
}
iが正しくすべての地域NSLogs「大丈夫監視領域」を得ます。地域の追加
はそう
double metres=20.0;
CLLocationDistance dist=metres;
CLLocationAccuracy acc=1.0;
CLRegion *reg=[[CLRegion alloc] initCircularRegionWithCenter:coordinate radius:dist identifier:landmarkObj.landmarkName];
[locationManager startMonitoringForRegion:reg desiredAccuracy:acc];
のように行われますが、コールバックがすべて
場所を更新- (void)locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Entered"
message:region.identifier
delegate:self
cancelButtonTitle:@"OK"
otherButtonTitles:nil, nil];
[alert show];
}
- (void)locationManager:(CLLocationManager *)manager didExitRegion:(CLRegion *)region
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Exited"
message:region.identifier
delegate:self
cancelButtonTitle:@"OK"
otherButtonTitles:nil, nil];
[alert show];
}
- (void)locationManager:(CLLocationManager *)manager didStartMonitoringForRegion:(CLRegion *)region
{
NSLog(@"started monitring for region: %@",region);
}
- (void) locationManager:(CLLocationManager *)manager monitoringDidFailForRegion:(CLRegion *)region withError:(NSError *)error
{
NSLog(@"%@",error);
}
を起動されませんが、正常に動作します。代わりに、領域を監視するために使用didUpdatToLocation:
[locationManager startUpdatingLocation];
が期待
更新としてコールバックdidUpdateToLocationをトリガします。 まだこれがうまくいかない理由を知りたい場合、地域監視で成功したことはほとんどないようです。
この問題の解決方法を見つけましたか?私は同じ問題を抱えていて、didStartMonitoringForRegionは発砲していません。 – Das
それは、私が必要とする正確さを私に与えることはできません。私は、すべてのdidUpdateToLocationコールバックの手動チェックを終了しました。これは、私が10地域しか追跡していなかったので、実現可能でした。 – tzl