6

これを使用する知識を知っている人はいますか:

- (void) startMonitoringForRegion:(CLRegion *)region desiredAccuracy:(CLLocationAccuracy)accuracy

私はそれを自分のプロジェクトに実装しようとしていますが:

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

呼ばれたことはないですか?

誰かがサンプルコードを持っているか、なぜこれが起こっているのか知っていますか?

私のコードは次のとおりです。独自の LocationManager クラスで次のようなメソッドを作成しました。

 - (void) locationManagerStartMonitoringRegion:(CLRegion *)region withAccuracy:(CLLocationAccuracy)accuracy {
    NSLog(@"Start Monitoring");
    [locationManager startMonitoringForRegion:region desiredAccuracy:accuracy];
    NSLog(@"Monitored Regions: %i", [[locationManager monitoredRegions] count]);
}

次に、次のように呼び出します。

CLLocationCoordinate2D coordinates = CLLocationCoordinate2DMake(51.116261, -0.853758);     
CLRegion *grRegion = [[CLRegion alloc] initCircularRegionWithCenter:coordinates radius:150 identifier:[NSString stringWithFormat:@"grRegion%i", value]];

[locationManager locationManagerStartMonitoringRegion:grRegion withAccuracy:kCLLocationAccuracyBest];

次の NSLog を取得します。

2011-01-30 19:52:26.409 TestingLocation[10858:307] 監視を開始

2011-01-30 19:52:27.103 TestingLocation[10858:307] 監視地域:

ただし、次の場所から NSLog を取得しないでください。

 - (void) locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region     {
    NSLog(@"Entered Region");
}

また

 - (void) locationManager:(CLLocationManager *)manager monitoringDidFailForRegion:(CLRegion *)region withError:(NSError *)error {
    NSLog(@"monitoringDidFailForRegion: %@",error);
}

ありがとう

4

5 に答える 5

5

地域の監視が機能するには、かなり遠くまで移動する必要があります。その現在の粒度は、ある基地局から別の基地局に引き継がれるタイミングに基づいているようです。私のテストでは、設定した小さな地域を確実に離れたことを登録するには、1 マイル以上移動する必要がありました。

于 2011-01-31T01:30:55.133 に答える
1

精度はios5で改善されています。

于 2011-09-13T06:23:44.317 に答える
1

答えは:

- (void) startMonitoringForRegion:(CLRegion *)region desiredAccuracy:(CLLocationAccuracy)accuracy

ios 6.o では非推奨です。代わりに `- (void) startMonitoringForRegion:(CLRegion *)region を使用してください。

ありがとう、アブドゥル

于 2013-07-15T05:49:46.983 に答える
0

インスタンスのセットアップ場所を確認する必要がありlocationManagerます。しかし、@Mark Adams は逃げようとしてlocationManagerいるので、現在のクラスをデリゲートとして設定して、メッセージを送り返すクラスを認識できるようにする必要があります。次のように簡単です。

locationManager.delegate = self;

于 2011-01-31T01:36:28.553 に答える