作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我以这种方式初始化locationManager:
if (!self.locManager)
{
self.locManager = [[CLLocationManager alloc] init];
self.locManager.delegate = self;
[locManager startMonitoringSignificantLocationChanges];
}
最佳答案
didUpdateToLocation
可能由于多种原因而更新,一种解决此问题的好策略是根据时间戳逐渐过滤结果,然后根据所需的准确性进行过滤。
苹果在LocateMe sample app中提供了一个很好的例子:
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
// test the age of the location measurement to determine if the measurement is cached
// in most cases you will not want to rely on cached measurements
NSTimeInterval locationAge = -[newLocation.timestamp timeIntervalSinceNow];
if (locationAge > 5.0) return;
// test that the horizontal accuracy does not indicate an invalid measurement
if (newLocation.horizontalAccuracy < 0) return;
// test the measurement to see if it is more accurate than the previous measurement
if (self.bestEffortAtLocation == nil || self.bestEffortAtLocation.horizontalAccuracy > newLocation.horizontalAccuracy)
{
// store the location as the "best effort"
self.bestEffortAtLocation = newLocation;
// test the measurement to see if it meets the desired accuracy
//
// IMPORTANT!!! kCLLocationAccuracyBest should not be used for comparison with location coordinate or altitidue
// accuracy because it is a negative value. Instead, compare against some predetermined "real" measure of
// acceptable accuracy, or depend on the timeout to stop updating. This sample depends on the timeout.
//
if (newLocation.horizontalAccuracy <= locationManager.desiredAccuracy) {
// we have a measurement that meets our requirements, so we can stop updating the location
//
// IMPORTANT!!! Minimize power usage by stopping the location manager as soon as possible.
//
[self stopUpdatingLocation:NSLocalizedString(@"Acquired Location", @"Acquired Location")];
}
}
}
关于iphone - 无需更改即可调用函数“didUpdateToLocation”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12772672/
这实际上是我问的问题的一部分here ,该问题没有得到答复,最终被标记为重复。 问题:我只需使用 @Autowired 注释即可使用 JavaMailSender。我没有通过任何配置类公开它。 @Co
我是一名优秀的程序员,十分优秀!