我的应用程序无法在北美的3G网络中确定经纬度坐标。当连接到Wi-Fi时,它可以完美地工作。这已经在使用iOS 5的AT&T和Verizon上得到了确认。在英国,o2的3G和Wi-Fi上都能正常工作。
我真的很困惑可能是什么原因。我认为我的代码对于精度相当宽容,但由于我在大西洋彼岸,我可能完全错了?
有人能指出我的代码中是否存在任何明显的错误吗?(我已经删除了一些不相关的方法。)
我真的很困惑可能是什么原因。我认为我的代码对于精度相当宽容,但由于我在大西洋彼岸,我可能完全错了?
有人能指出我的代码中是否存在任何明显的错误吗?(我已经删除了一些不相关的方法。)
static NSTimeInterval MaxLocationAge = 60.0; // Seconds.
static CLLocationAccuracy DesiredHorizontalAccuracy = 200.0; // Meters.
static NSTimeInterval UpdateTimeout = 30.0; // Seconds.
@implementation AFLocation
@synthesize locationManager = _locationManager, delegate = _delegate, bestEffortAtLocation = _bestEffortAtLocation, updateStartedAt = _updateStartedAt;
- (id)init
{
self = [super init];
if (self) {
CLLocationManager *manager = [[CLLocationManager alloc] init];
self.locationManager = manager;
[manager release];
self.locationManager.delegate = self;
self.locationManager.distanceFilter = kCLDistanceFilterNone;
self.locationManager.desiredAccuracy = kCLLocationAccuracyBestForNavigation;
}
return self;
}
- (void)update
{
self.updateStartedAt = [NSDate date];
isUpdating = YES;
[self.locationManager startUpdatingLocation];
}
- (void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation {
if ([[NSDate date] timeIntervalSinceDate:self.updateStartedAt] > UpdateTimeout) {
[self.locationManager stopUpdatingLocation];
if (isUpdating) {
[self updateDidTimeout];
}
isUpdating = NO;
}
NSTimeInterval locationAge = -[newLocation.timestamp timeIntervalSinceNow];
if (locationAge > MaxLocationAge) {
return;
}
if (newLocation.horizontalAccuracy < 0) {
return;
}
if (self.bestEffortAtLocation == nil || self.bestEffortAtLocation.horizontalAccuracy > newLocation.horizontalAccuracy) {
self.bestEffortAtLocation = newLocation;
if (newLocation.horizontalAccuracy <= DesiredHorizontalAccuracy) {
self.bestEffortAtLocation = nil;
isUpdating = NO;
[self.locationManager stopUpdatingLocation];
[self didUpdateWithDesiredAccuracyToLocation:newLocation];
}
}
}
@end