[英]Not able to set region for monitoring using CLCircular Region in swift
我嘗試使用代碼在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多個區域。 我只監視一個區域。 誰能告訴我我要去哪里錯了? 先感謝您 。
它的工作。 您可能設置了錯誤的半徑。
此代碼段對我有用:
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)
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.