相关疑难解决方法(0)

locationManager:didUpdateLocations:总是被多次调用

我在视图出现时开始更新当前位置,并在每次locationManager:didUpdateLocations:调用时停止更新位置.但为什么locationManager:didUpdateLocations:总是多次被召唤?我错过了什么?

#import "ViewController.h"

@interface ViewController (){
    CLLocationManager *locationManager; // location manager for current location
}
@end

@implementation ViewController
- (void)viewDidLoad
{
    [super viewDidLoad];
}

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
    [self startUpdatingCurrentLocation];
}

- (void)startUpdatingCurrentLocation
{
    if (!locationManager)
    {
        locationManager = [[CLLocationManager alloc] init];
        [locationManager setDelegate:self];
        locationManager.distanceFilter = 10.0f; // we don't need to be any more accurate than 10m
    }
    [locationManager startUpdatingLocation];
}

-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations{
    [locationManager stopUpdatingLocation];
}
@end
Run Code Online (Sandbox Code Playgroud)

iphone cllocationmanager ios

6
推荐指数
1
解决办法
5462
查看次数

StopUpdatingLocation方法不适用于iOS5

我正在研究地图应用,

我尝试使用[locationManager stopUpdatingLocation];方法来停止Location服务.

它似乎在iOS4.3中运行良好,但在iOS5中,它无法正常工作.

请任何人建议我如何在iOS5中停止位置服务?

iphone cocoa-touch objective-c ios4 ios5

4
推荐指数
2
解决办法
4044
查看次数

标签 统计

iphone ×2

cllocationmanager ×1

cocoa-touch ×1

ios ×1

ios4 ×1

ios5 ×1

objective-c ×1