问题
My question is regarding the creation of regions for regionMonitoring in iOS 5. Can new regions be created based on user of the app's current location? Or do all regions need to be predefined by the developer in the applications binary?
I know you can have certain regions register based on the users current location, because the os puts a limit on the number of regions that the phone/app can be monitoring at one time, and you should only register the regions within close proximity to the users current location... but can a region (previously undefined) be created on the fly based on the users location?
use case example:
users app spins up coreLocation to get an accurate set of coordinates, once we have accurate coords, corelocation shuts down to save battery. An event needs to occur when the user leaves the area so we want to know when the user moves x units of distance. Can a region be created x units of distance around this users current location, so we can start monitoring for did exit region?
I put in a good amount of research but could not find an answer... and unfortunately I am not very familiar with regionMonitoring.
Thanks :)
回答1:
Theoretically, You can monitor any region any time, these regions don't need to be predefined, you may use following code to create and monitor your required regions pragmatically,
CLLocationCoordinate2D center = CLLocationCoordinate2DMake(location.coordinate.latitude, location.coordinate.longitude);
CLRegion *region = [[CLRegion alloc] initCircularRegionWithCenter:center radius:50.0f identifier:identifier];
[self.locationManager startMonitoringForRegion:region desiredAccuracy:kCLLocationAccuracyBest];
PS: Region monitoring implementation is not as much useful as apple advertise, to my understanding it relies on cell change events (again to save the battery). I'm not happy even with the results of default Reminders app (location based reminders) both on iPhone 4 and 4s.
来源:https://stackoverflow.com/questions/9946952/ios-5-region-monitoring-can-new-regions-be-created-based-on-users-current-coord