【问题标题】:CoreLocation start Monitoring For multi RegionsCoreLocation 启动多区域监控
【发布时间】:2013-06-07 03:06:00
【问题描述】:

如何使用 locationManager startMonitoringForRegion 方法开始监控多个区域

例如,我要监控三个区域

CLLocationCoordinate2D centreLoc = {28.965243, 48.149724};
CLLocationDistance regionRadius = 200.00;
CLRegion *grRegion = [[CLRegion alloc] initCircularRegionWithCenter:centreLoc radius:regionRadius identifier:@"grRegion1"];


CLLocationCoordinate2D centreLoc2 = {28.765243, 48.149724};
CLLocationDistance regionRadius2 = 200.00;
CLRegion *grRegion2 = [[CLRegion alloc] initCircularRegionWithCenter:centreLoc2 radius:regionRadius2 identifier:@"grRegion2"];

CLLocationCoordinate2D centreLoc3 = {28.865243, 48.149724};
CLLocationDistance regionRadius3 = 200.00;
CLRegion *grRegion3 = [[CLRegion alloc] initCircularRegionWithCenter:centreLoc3 radius:regionRadius3 identifier:@"grRegion3"];

CLLocationAccuracy acc2=kCLLocationAccuracyBest;
[locationManager startMonitoringForRegion:grRegion2 desiredAccuracy:acc2];

如何启动这三个区域的监控???

【问题讨论】:

  • 只需为每个区域调用 startMonitoringForRegion。
  • 如果我有很多地区,我该怎么做,请举个例子
  • 您可以为每个区域调用startMonitoringForRegion。
  • 我试过这个,但它不起作用

标签: ios xcode location core-location locationmanager


【解决方案1】:

你在正确的轨道上。

首先,您的坐标应该是双精度值,您使用的是浮点值。

其次,您需要为纬度和经度创建单独的数组,然后在索引 i 处获取这些值。

这应该可行。

for (int i = 0; i < [AllRegionsArray count]; i++) {
    NSArray *longLati = [allRegionsArray objectAtIndex:i];
    NSMutableArray *latArray = longLati objectAtIndex:0];
    NSMutableArray *longArray = longLati objectAtIndex:1];
    lutiuid = [latArray objectAtIndex:i];
    longtuid = [longArray objectAtIndex:i];

    CLLocationCoordinate2D centreLoc = [CLLocation2DMake([[lutiuid] doubleValue], [[longtuid] doubleValue]);
//iOS 6
    CLRegion *grRegion = [[CLRegion alloc] initWithCenter:centreLoc radius:200 identifier://yourIdentifier, I used the string of the address];
//iOS 7
CLCircularRegion *region = [[CLCircularRegion alloc] initWithCenter:coordinate radius:radius identifier:identifier];
    locationManager.desiredAccuracy = kCLLocationAccuracyBest;
    [locationManager startMonitoringForRegion:grRegion];
    NSLog(@"monotoring regions:%@", locationManager.monitoredRegions);

【讨论】:

  • 我遇到了和提问者类似的问题,但是这个解决方案仍然没有为我解决问题。即使您调用 startMonitoringForRegion,locationManager.monitoredRegion 计数也会返回 0
  • 您的数组是否返回正确的纬度和经度值?
  • 当我使用 CLCircularRegion 而不是 CLRegion(已弃用)时,我的问题得到了解决。
  • 我不记得到底是什么解决了这个问题,但我也做了一些别的事情来解决这个问题。 CLRegion 现在也可以使用了。
  • 感谢您指出这一点,当我最初回答我们仍在使用 iOS 6 时,我已经编辑了答案以反映这一点。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-07-04
  • 1970-01-01
  • 2022-01-23
  • 1970-01-01
  • 2014-04-19
  • 2017-12-10
  • 1970-01-01
相关资源
最近更新 更多