问题
I'm looking for a way to get a background location update every n minutes in my iOS application.. now i am getting update in every second.. can i change one second to three or four second or every minute...
Here is my code:
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {
if([self.delegate conformsToProtocol:@protocol(GPSLocationDelegate)]) {
// Check if the class assigning itself as the delegate conforms to our protocol. If not, the message will go nowhere. Not good.
[self.delegate locationUpdate:newLocation];
NSLog(@"location manager");
/// alert for check msg ////
////////////////////////////
}
}
回答1:
You can not do it. Alternatively you can achieve it by below way. When you get location updates, it will have the timestamp associated with it.
Cache the time stamp on first location update. When you receive the second location update, compare the difference and check. If it is greater than your threshold limit, call your delegate and update the cached time stamp with updated location's time stamp.
回答2:
You could stop the location manager when you receive a new location and schedule a timer to start it again 60 seconds past. The only problem will be that you won't get the events triggered exactly after each 60 seconds, but it may be ok.
And also be careful when you stop your location manager, as I think that its first event can be invalid (giving you just a copy of your last location), so may be you will have to keep it running for 5-10 seconds before stopping it and scheduling the next trigger.
Good luck with that!
回答3:
Location updates are asynchronous, you can't control the frequency in which they appear.
来源:https://stackoverflow.com/questions/11688976/how-to-change-gps-update-time-in-ios