Skip to content

Instantly share code, notes, and snippets.

@donly
Created May 25, 2012 03:37
Show Gist options
  • Save donly/2785615 to your computer and use it in GitHub Desktop.
Save donly/2785615 to your computer and use it in GitHub Desktop.
#pragma mark - CLLocationManagerDelegate
- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error {
switch (error.code) {
case kCLErrorLocationUnknown:
NSLog(@"The location manager was unable to obtain a location value right now.");
break;
case kCLErrorDenied:
NSLog(@"Access to the location service was denied by the user.");
break;
case kCLErrorNetwork:
NSLog(@"The network was unavailable or a network error occurred.");
break;
default:
NSLog(@"未定义错误");
break;
}
}
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
NSLog(@"oldLocation.coordinate.timestamp:%@", oldLocation.timestamp);
NSLog(@"oldLocation.coordinate.longitude:%f", oldLocation.coordinate.longitude);
NSLog(@"oldLocation.coordinate.latitude:%f", oldLocation.coordinate.latitude);
NSLog(@"newLocation.coordinate.timestamp:%@", newLocation.timestamp);
NSLog(@"newLocation.coordinate.longitude:%f", newLocation.coordinate.longitude);
NSLog(@"newLocation.coordinate.latitude:%f", newLocation.coordinate.latitude);
NSTimeInterval interval = [newLocation.timestamp timeIntervalSinceDate:oldLocation.timestamp];
NSLog(@"%lf", interval);
// 取到精确GPS位置后停止更新
if (interval < 3) {
// 停止更新
[locationManager stopUpdatingLocation];
}
latitudeLabel.text = [NSString stringWithFormat:@"%f", newLocation.coordinate.latitude];
longitudeLabel.text = [NSString stringWithFormat:@"%f", newLocation.coordinate.longitude];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment