我正在使用locationManager:didStartMonitoringForRegion:
進行區域監控。有時回調包含錯誤的區域,即使在CLLocationManager.monitoredRegions
中顯示的右側區域也是如此。locationManager:didStartMonitoringForRegion:錯誤區域回調
的locationManager:didStartMonitoringForRegion:
消息:
- (void)locationManager:(CLLocationManager *)manager didStartMonitoringForRegion:(CLRegion *)region {
NSLog(@"Started monitoring %@ region", region.identifier);
NSLog(@"Monitored regions: %@", self.locationManager.monitoredRegions);
}
這裏一個示例輸出(具有改變經度/ latidue保存地方)
2013-12-13 20:01:34.047 N[] Started monitoring Hamburg region
2013-12-13 20:01:34.048 N[] Monitored regions: {(
CLCircularRegion (identifier:'Hamburg', center:<+47.0,+8.1>, radius:1000.00m),
CLCircularRegion (identifier:'Zürich', center:<+47.0,+8.0>, radius:500.00m),
CLCircularRegion (identifier:'St.Gallen', center:<+47.0,+9.0>, radius:5000.00m)
)}
2013-12-13 20:01:42.070 N[] Started monitoring Hamburg region
2013-12-13 20:01:42.072 N[] Monitored regions: {(
CLCircularRegion (identifier:'Hamburg', center:<+47.0,+8.1>, radius:1000.00m),
CLCircularRegion (identifier:'Zürich', center:<+47.0,+8.0>, radius:500.00m),
CLCircularRegion (identifier:'St.Gallen', center:<+47.0,+9.0>, radius:5000.00m)
)}
2013-12-13 20:01:46.837 N[] Started monitoring Hamburg region
2013-12-13 20:01:46.839 N[] Monitored regions: {(
CLCircularRegion (identifier:'Hamburg', center:<+47.0,+8.1>, radius:1000.00m),
CLCircularRegion (identifier:'Zürich', center:<+47.0,+8.0>, radius:500.00m),
CLCircularRegion (identifier:'St.Gallen', center:<+47.0,+9.0>, radius:5000.00m)
)}
我開始didUpdateLocations
監視其被稱爲我打電話startMonitoringSignificantLocationChanges
- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations{
NSLog(@"%s", __PRETTY_FUNCTION__);
[manager stopMonitoringSignificantLocationChanges];
if (locations && [locations count]){
CLLocation* position = [locations lastObject];
NSLog(@"New Location latitude: %f longitude %f", position.coordinate.latitude, position.coordinate.longitude);
//self.geofences.allValues is containing Hamburg,Zürich and St.Gallen
for(CLCircularRegion *geofence in self.geofences.allValues) {
if(![self.locationManager.monitoredRegions containsObject:geofence]){
[self.locationManager startMonitoringForRegion:geofence];
}
if([geofence containsCoordinate:[position coordinate]]){
[self locationManager:manager didEnterRegion:geofence];
}
}
}
}
該didEnterRegion
爲@synchronized
以保證原子性。
任何想法?
你的意思是錯誤的?似乎你留在漢堡,胡默爾,胡默爾:-)在這種情況下還應該返回哪個區域? – thorb65
我不知道你想解決什麼問題。如何註冊地區?向我們展示一些您的代碼並澄清您的問題。 –
@DeanDavids我已經添加了一些代碼。問題是我開始監測3個地區(Hambug,蘇黎世和St.Gallen)。所以在此之後,我期待3個回調與這些地區。有時我得到三個(不同的)監控區域,有時候我沒有(如上所示) – cakl