DrK*_*Key 4 objective-c cllocationmanager ios
我需要知道CLLocationManager(在这种情况下称为gps)的实例是否正在更新调用正确方法的位置
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
Run Code Online (Sandbox Code Playgroud)
在我的情况下,完整的方法是:
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
//NSLog(@"didUpdateToLocation: %@", newLocation);
currentLocation = newLocation;
if (currentLocation != nil) {
longitude.text = [NSString stringWithFormat:@"%.3f", currentLocation.coordinate.longitude];
latitude.text = [NSString stringWithFormat:@"%.3f", currentLocation.coordinate.latitude];
}
address.text = NULL;
[activityIndicator setHidden:NO];
[activityIndicator startAnimating];
NSLog(@"Resolving the Address");
[geocoder reverseGeocodeLocation:currentLocation completionHandler:^(NSArray *placemarks, NSError *error) {
//NSLog(@"Found placemarks: %@, error: %@", placemarks, error);
if (error == nil && [placemarks count] > 0) {
placemark = [placemarks lastObject];
[address sizeToFit];
address.text = [NSString stringWithFormat:@"%@, %@\n%@ %@\n%@",
[self sanitizedDescription:placemark.thoroughfare],
[self sanitizedDescription:placemark.subThoroughfare],
[self sanitizedDescription:placemark.postalCode],
[self sanitizedDescription:placemark.locality],
[self sanitizedDescription:placemark.country]];
if (address.text != NULL)
{
gpsTimer = [NSTimer scheduledTimerWithTimeInterval:10
target:gps
selector:@selector(startUpdatingLocation)
userInfo:nil
repeats:NO];
[address sizeToFit];
[gps stopUpdatingLocation];
}
} else {
NSLog(@"%@", error.debugDescription);
}
} ];
}
Run Code Online (Sandbox Code Playgroud)
我能怎么做?
提前致谢 :)
| 归档时间: |
|
| 查看次数: |
4574 次 |
| 最近记录: |