2016-05-19 13 views
0

Я пытаюсь установить CLCircularRegion в методе didUpdateLocations с использованием кодане в состоянии установить регион для мониторинга с использованием CLCircular Регион в быстрой

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 регионов. Я контролирую только один регион. Может ли кто-нибудь предложить мне, где я ошибаюсь? Заранее спасибо .

ответ

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

радиус я поставил на 10 .. –

+0

я должен установить некоторый минимальный радиус, и если да, то пожалуйста, дайте мне знать радиус –

+0

Я попытался с 100 а также –

 Смежные вопросы

  • Нет связанных вопросов^_^