“的准确性;“区域监测”;在iOS 6上

“的准确性;“区域监测”;在iOS 6上,ios,location,ios-simulator,region,cllocation,Ios,Location,Ios Simulator,Region,Cllocation,我正在尝试制作一个基于位置的应用程序,需要在打开后不断更新位置。我正在寻找一种方法,在应用程序关闭时将位置保留在后台,我发现这不是最好的方法,因为它会很快耗尽任何iPhone的电池电量 长话短说,据我所知,我发现“区域监控”与苹果应用程序“提醒”相同,同样适用于位置。然后,我使用该选项测试我的应用程序,我意识到在模拟器中,“从不”输入方法“didEnterRegion”,尽管它是正确创建的: -(void) locationManager: (CLLocationManager *) manag

我正在尝试制作一个基于位置的应用程序,需要在打开后不断更新位置。我正在寻找一种方法,在应用程序关闭时将位置保留在后台,我发现这不是最好的方法,因为它会很快耗尽任何iPhone的电池电量

长话短说,据我所知,我发现“区域监控”与苹果应用程序“提醒”相同,同样适用于位置。然后,我使用该选项测试我的应用程序,我意识到在模拟器中,“从不”输入方法“didEnterRegion”,尽管它是正确创建的:

-(void) locationManager: (CLLocationManager *) manager didEnterRegion: (CLRegion *) region
 {
     NSLog (@ "entering the region");
     CLLocation * location1 = manager.location;
     CLLocation * location2 = [[CLLocation alloc] initWithLatitude: latitud.doubleValue longitude: longitud.doubleValue];
 }
我终于意识到该方法被调用了,但只有当我离开大部分区域,回到该区域时,我才意识到该方法不起作用,因为我已经在该位置(所有这些都在模拟器中),奇怪的是,它不是,模拟器的位置离监控区域有几英里远!这让我觉得这是精度的问题,尽管创建半径为50或100米的区域会扩展3或4公里,所以我没用

有没有人经历过这种情况,知道iOS 6模拟器是否存在此错误或精度问题?我还没有在iPhone上直接测试它的开发者许可证,我也不想买它,因为我的应用程序还远没有完成,我非常感谢在这个话题上的任何帮助

提前感谢。

区域监测工作(通常)与“重大位置变化”定位服务的工作基础相同。也就是说,它使用了细胞塔的位置;苹果公司建议,你通常可以预计精度在1公里左右,但警告说,实际精度将随你所在地区的基站密度而变化。您可以在on Core位置找到有关此主题的更多背景信息


可能是可行的——我没有尝试过——使用区域监控(唤醒你的应用程序)来大致猜测用户的位置,然后在
CLLocationManager
中使用更高精度的模式来获得更精确的修复。

在完成时,我意识到区域监控的准确性在大多数情况下都是好的,但在模拟器中可能会很棘手,因为它没有GPS或手机硬件,不管怎样,当我在设备中使用“区域监控”时,即使在模拟路线中,功能也能正常工作


为了更准确,我将CLLocationManager的“startUpdatingLocation”方法调用到“didEnterRegion”方法中,该方法对我来说很有效。

我建议进行实际的地面测试。区域监控精度因测试位置而异


第二种选择是使用区域监控来唤醒应用程序并启动标准位置服务。为此,您需要在后台运行应用程序的权限。苹果可能不会批准。我们的应用程序使用这种方法被拒绝。

DidEnterRegion和ExitRegion的结果不太准确。精度约为+,-150米

但是-(void)位置管理器:(CLLocationManager*)管理器更新位置:(NSArray*)位置 非常准确。使用此选项可以找出您所在区域的坐标/当前位置

CLLocation *currentLocation = [locations lastObject];

 if ([self.ARegionYouSetBeforeHand containsCoordinate:currentLocation.coordinate])
{
 //you arrived at this region!!
}

我在iPhone 5C上使用手机塔移动数据进行区域监控时也遇到过同样的问题,禁用了WiFi,我很快就习惯于打电话给didEnterRegion,当时我离监控点1.95公里,我将区域半径保持在100.0米。这还为时过早

苹果有一些阈值是由目前可用的硬件和定位技术决定的。所以对我来说,它可能是1800米左右的早期值

我建议保持radius最小值(例如,对于500.0区域为25.0),或者如果这是非常宝贵的通知,请使用didUpdateLocations委托方法确定您的区域并通知相同的区域

问候,,
Kaushik

我发现内置的区域监控不够精确,无法满足我的需要。如果您需要更高的精确度,请先适当设置精确度,然后您可以使用以下方法:

(使用与@coolcool1994相同的方法,但更深入一点,并使用Swift 2.1。请记住设置
CLLocationManager
及其委托(以下功能将驻留在其中),并开始接收位置更新)

var-activeRegions=Set()
变量监视区域=[
CLCircularRegion(中心:CLLocationCoordinate2D(纬度:0.0,经度:0.0),
半径:300,标识符:“区域1”),
CLCircularRegion(中心:CLLocationCoordinate2D(纬度:0.0,经度:0.0),
半径:300,标识符:“区域2”)
]
func manuallyUpdateActiveRegionsFromLocation(位置:CLLocation){
//(可选)显式拒绝不需要的位置更新
//设置location manager代理所需的准确性应该足够了
让maxOldTime=300//5分钟
让最小精度=300//300米
如果abs(location.timestamp.timeIntervalSinceNow)>maxOldTime
||位置.水平精度>最小精度{
返回
}
用于监视区域中的监视区域{
如果监视区域包含坐标(位置坐标){
activeRegions.insert(monitoredRegion.identifier)
}否则{
activeRegions.remove(monitoredRegion.identifier)
}
}
}
func locationManager(管理器:CLLocationManager,didUpdateLocations位置:[CLLocation]){
如果let location=locations.last{
手动从位置(位置)更新每个活动区域
}
}

MK MapView上的预定义GPS精度

  • kCLLocationAccuracyBestForNavigation–使用尽可能高的值
    通过附加传感器数据提高精度水平

  • kCLLocationAccuracyBest–建议的最高级别
    使用电池电源运行的设备的精度

  • KCLLOCATIONACURACYNEARESTENMERS-精确到10米以内

  • CLLOCATIONACCURACYHUNDREDMETS–精确到100米以内

  • KCLLOCATIONACURACYKI
    var activeRegions = Set<String>()
    var monitoredRegions = [
      CLCircularRegion(center: CLLocationCoordinate2D(latitude: 0.0, longitude: 0.0),
        radius: 300, identifier: "Region1"),
      CLCircularRegion(center: CLLocationCoordinate2D(latitude: 0.0, longitude: 0.0),
        radius: 300, identifier: "Region2")
    ]
    
    func manuallyUpdateActiveRegionsFromLocation(location: CLLocation){
      // Optionally explicitly reject unwanted location updates
      // Setting the location manager delegate's desiredAccuracy should be enough
      let maxOldTime = 300 //5 minutes
      let minAccuracy = 300 //300 metres
      if abs(location.timestamp.timeIntervalSinceNow) > maxOldTime
        || location.horizontalAccuracy > minAccuracy {
          return
      }
    
      for monitoredRegion in monitoredRegions {
        if monitoredRegion.containsCoordinate(location.coordinate) {
          activeRegions.insert(monitoredRegion.identifier)
        } else {
          activeRegions.remove(monitoredRegion.identifier)
        }
      }
    
    }
    
    func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
      if let location = locations.last {
        manuallyUpdateActiveRegionsFromLocation(location)
      }
    }
    
    var locationManager: CLLocationManager = CLLocationManager()
    
        //MapView Location
        locationManager.delegate = self
        locationManager.desiredAccuracy = kCLLocationAccuracyNearestTenMeters
        locationManager.requestWhenInUseAuthorization()
        locationManager.startUpdatingLocation()
        locationManager.startUpdatingHeading()