我正在尝试为我的用户找到准确的纬度/经度坐标。我参考了文档并了解了 LocateMe 示例项目。我正在尝试编辑代码,以便弹出警报,让用户知道位置信息是否准确。
我有下面的代码,但警报总是说用户的位置信息不准确(“位置错误”)。有谁知道我做错了什么?
我刚刚意识到 Apple 的示例代码包括以下行:[setupInfo setObject:[NSNumber numberWithDouble:kCLLocationAccuracyHundredMeters] forKey:kSetupInfoKeyAccuracy];
我将如何编辑下面的代码以等待kCLLocationAccuracyNearestTenMeters
. 如果可能的话,我宁愿不必引用另一个视图控制器,而是能够将它直接包含在方法中。
任何帮助都会很棒。谢谢!
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation
*)newLocation fromLocation:(CLLocation *)oldLocation {
//CAN I PUT THE DESIRED ACCURACY HERE?
locationManager.desiredAccuracy = kCLLocationAccuracyHundredMeters; // 100 m
[locationMeasurements addObject:newLocation];
NSTimeInterval locationAge = -[newLocation.timestamp timeIntervalSinceNow];
if (locationAge > 5.0) return;
if (newLocation.horizontalAccuracy < 0) return;
if (bestEffortAtLocation == nil || bestEffortAtLocation.horizontalAccuracy >
newLocation.horizontalAccuracy) {
self.bestEffortAtLocation = newLocation;
if (newLocation.horizontalAccuracy <= locationManager.desiredAccuracy) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Location Good"
message:@"OK" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil,
nil];
[alert show];
return;
}
else {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Location Bad"
message:@"OK" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil,
nil];
[alert show];
return;
}
}
}