0

I try to set a CLCircularRegion in didUpdateLocations method using the code

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)
}

error occurs on the line

locationManager.startMonitoringForRegion(region) 

and the error that occurs is

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

the coordinates and the radius is correctly set to the region . I am not monitoring 20+ regions as well . I am monitoring only one region . Can anyone suggest me where am I going wrong ? Thank you in advance .

AnxiousMan
  • 578
  • 2
  • 8
  • 25

1 Answers1

0

Its working. You might have set a wrong radius.

This code snippet is working for me:

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)
}
jay
  • 3,517
  • 5
  • 26
  • 44
  • should i set some minimum radius , and if yes , kindly let me know the radius – AnxiousMan May 19 '16 at 08:04
  • ` : the center of the region is CLLocationCoordinate2D(latitude: 12.828343149999995, longitude: 80.051109009999976) and the radius of the region is 1000.0` .. but still the error persists. – AnxiousMan May 19 '16 at 08:10