我尝试使用代码在didUpdateLocations方法中设置CLCircularRegion
<div>
<div id='ajax-1'>
</div>
<div id='ajax-2'>
</div>
...
</div>
<div id='loading'>loading...</div>
行出现
错误
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)
坐标和半径正确设置为该区域。我也没有监控20多个地区。我只监控一个地区。任何人都可以建议我哪里出错了?提前谢谢。
答案 0 :(得分: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)
}