ios - 注册区域 ios 时是否需要 startLocationUpdates?

标签 ios mkmapview

在我的应用程序中,我注册了一些 CLRegion。我的全部功能在于这些功能:

- (void)locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region {
    NSLog(@"Entered Region - %@", region.identifier);
    [self showRegionAlert:@"Entering Region" forRegion:region.identifier];
}

- (void)locationManager:(CLLocationManager *)manager didExitRegion:(CLRegion *)region {
    NSLog(@"Exited Region - %@", region.identifier);
    [self showRegionAlert:@"Exiting Region" forRegion:region.identifier];
}

- (void)locationManager:(CLLocationManager *)manager didStartMonitoringForRegion:(CLRegion *)region {
    NSLog(@"Started monitoring %@ region", region.identifier);
}

这个函数存在于我的代码中,但我没有在这里做任何事情:

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
    NSLog(@"Location Update:%@",[NSString stringWithFormat:@"%f,%f",newLocation.coordinate.latitude, newLocation.coordinate.longitude]);
}

我的问题是:

这个初始化是必要的吗?

- (void)initializeLocationUpdates {
    [_locationManager startUpdatingLocation];
}

当您只想考虑区域时?

最佳答案

不,但是您必须为每个要监视的区域调用 startMonitoringForRegion:。像这样:

CLRegion *region = // Set up your region
self.locationManager.delegate = self; // Make sure you are set as the location manager's delegate
[self.locationManager startMonitoringForRegion: region]; // Start monitoring the region

请参阅 this page 上的 startMonitoringForRegion: 文档

关于ios - 注册区域 ios 时是否需要 startLocationUpdates?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21065646/

相关文章:

ios - 如何 "generify"Swift 中的闭包类型别名?

iphone - 如何解码 NSString 中的 html 编码字符?

iOS Swift - 自定义 UITableViewCell

ios - 如何将 MKMapView 的单例类设置为 Storyboard 中的 map ?

ios - 如何切换 iOS 应用程序的构建

ios - iOS 8分享扩展。如何使图像成为必需但文本可选

objective-c - 将 mapView.userLocation.location.coordinate.longitude 保存到 sqlite 数据库中

ios - IOS MapView中有没有注解标题回调函数或者设置目标的方法?

ios - MKMapView setVisibleMapRect 未设置(有时)

ios - 从ios中的经纬度获取地址