0

我尝试使用代码在 didUpdateLocations 方法中设置 CLCircularRegion

func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
    NSLog("Location Updated from did Update Locations")
    let persist = Persistence()
    let currentLocation : CLLocation = locations[0]
    let latitude : Double = currentLocation.coordinate.latitude
    let Longitude : Double = currentLocation.coordinate.longitude
    let regionID = "GeoFenceTrack"
    let region : CLCircularRegion = CLCircularRegion.init(center: CLLocationCoordinate2DMake(latitude, Longitude), radius: Double(persist.getObject(mdmiosagent_Constants.LOCATIONRADIUS))!, identifier: regionID)

    NSLog("the center of the region is \(region.center) and the redius of the region is \(region.radius)")
    self.sendLocation(currentLocation)
    locationManager.desiredAccuracy = kCLLocationAccuracyHundredMeters
    locationManager.delegate = self
    locationManager.startMonitoringForRegion(region)
}

线上发生错误

locationManager.startMonitoringForRegion(region) 

并且发生的错误是

********* iPad *******[4018] <Warning>: Failed for region Error Domain=kCLErrorDomain Code=5 "(null)"

坐标和半径正确设置为区域。我也没有监控 20 多个地区。我只监视一个区域。谁能建议我哪里出错了?先感谢您 。

4

1 回答 1

0

它的工作。您可能设置了错误的半径。

此代码段对我有用:

func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation])
{
    NSLog("Location Updated from did Update Locations")
    let currentLocation : CLLocation = locations[0]
    let latitude : Double = currentLocation.coordinate.latitude
    let Longitude : Double = currentLocation.coordinate.longitude
    let regionID = "GeoFenceTrack"
    let region : CLCircularRegion = CLCircularRegion.init(center: CLLocationCoordinate2DMake(latitude, Longitude), radius: Double(1000), identifier: regionID)

    NSLog("the center of the region is \(region.center) and the redius of the region is \(region.radius)")
    //self.sendLocation(currentLocation)
    locationManager.desiredAccuracy = kCLLocationAccuracyHundredMeters
    locationManager.delegate = self
    locationManager.startMonitoringForRegion(region)
}
于 2016-05-19T08:01:12.750 回答