gpt4 book ai didi

ios - 检查 CLLocationManager 的实例是否为 UpdatingLocation

转载 作者:可可西里 更新时间:2023-11-01 05:05:47 26 4
gpt4 key购买 nike

我需要知道 CLLocationManager 的实例(在本例中称为 gps)是否正在调用正确的方法来更新位置

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation

在我的例子中,完整的方法是:

- (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);
}
} ];

}

我该怎么办?

提前致谢:)

最佳答案

将您的 CLLocationManager 子类化并添加一个 BOOL,当您的委托(delegate)方法被调用时将其设置为 yes...

您也可以简单地告诉您的位置管理器在委托(delegate)方法中停止

关于ios - 检查 CLLocationManager 的实例是否为 UpdatingLocation,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20144238/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com