gpt4 book ai didi

objective-c - didUpdateToLocation 停止调用

转载 作者:行者123 更新时间:2023-11-29 04:19:16 26 4
gpt4 key购买 nike

下面的方法

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

调用 1 或 2 次,然后就不再调用了...为什么?

 -(void) startLocation {
if (locationManager == nil)
locationManager = [[CLLocationManager alloc] init];

locationManager.delegate = self;
locationManager.desiredAccuracy = kCLLocationAccuracyNearestTenMeters;
locationManager.distanceFilter = 10;

[locationManager startUpdatingLocation];
}

和:

       - (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {
contadorSegundos++;
float diferencaLatitude = 0;
float diferencaLongitude = 0;
NSLog(@"old latitude: %f", oldLocation.coordinate.latitude);
NSLog(@"old longitude: %f", oldLocation.coordinate.longitude);


NSLog(@"new longitude: %f", newLocation.coordinate.longitude);
NSLog(@"old latitude: %f", newLocation.coordinate.latitude);

if(oldLocation) {
if(oldLocation.coordinate.latitude > newLocation.coordinate.latitude)
diferencaLatitude = oldLocation.coordinate.latitude - newLocation.coordinate.latitude;
else if(newLocation.coordinate.latitude > oldLocation.coordinate.latitude)
diferencaLatitude = newLocation.coordinate.latitude - oldLocation.coordinate.latitude;
}

if (oldLocation) {

if(oldLocation.coordinate.longitude > newLocation.coordinate.longitude)
diferencaLongitude = oldLocation.coordinate.longitude - newLocation.coordinate.longitude;
else if(newLocation.coordinate.longitude > oldLocation.coordinate.longitude)
diferencaLongitude = newLocation.coordinate.longitude - oldLocation.coordinate.longitude;
}

//NSLog(@"dif lat %f", diferencaLatitude);

//NSLog(@"dif long %f", differencaLongitude);

CLLocationCoordinate2D coord;
if ((diferencaLatitude > 1) || (diferencaLongitude > 1)) {
_emMovimento = YES;
NSLog(@"em movimento");
}
else {
if(contadorSegundos > 10) {
_emMovimento = NO;
contadorSegundos = 0;
NSLog(@"parado");
}
}

coord.longitude = newLocation.coordinate.longitude;
coord.latitude = newLocation.coordinate.latitude;
_latitude = coord.latitude;
_longitude = coord.longitude;

NSLog(@"latitude: %f", _latitude);
NSLog(@"longitude: %f", _longitude);
MKReverseGeocoder *geocoder = [[MKReverseGeocoder alloc] initWithCoordinate:coord];
[geocoder setDelegate:self];
[geocoder start];

最佳答案

这个问题是因为ARC自动释放了LocationManager对象。

关于objective-c - didUpdateToLocation 停止调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13204823/

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