0

次のコードがあります。

- (void) viewWillAppear {
    [self startSignificantChangeUpdates];
}



- (void)startSignificantChangeUpdates
{


    if ([CLLocationManager locationServicesEnabled])
    {
        NSLog(@"start significant changes");

        if (nil == locationManager)
            locationManager = [[CLLocationManager alloc] init];

        locationManager.delegate = self;
        [locationManager startMonitoringSignificantLocationChanges];
    }
}


problem is that the location manage is not  calling its delegate function 
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {

私に何ができる?

4

3 に答える 3

1

.h ファイル内:

#import <CoreLocation/CoreLocation.h>

@interface ViewController : UIViewController <CLLocationManagerDelegate>

.m ファイルで:

@implementation ViewController {
    // This is a private variable, used within this file only
    CLLocationManager *locationManager;
}

-(void)viewDidLoad {
    locationManager = [[CLLocationManager alloc] init];
}

-(void)viewWillAppear {
    // If the delegate is still not being set, try putting this code into viewDidAppear
    locationManager.delegate = self;
    locationManager.desiredAccuracy = kCLLocationAccuracyBest;
    [locationManager startUpdatingLocation];
}

-(void)locationManger:(CLLocationManager *)manager didFailWithError:(NSError *)error {
    NSLog(@"didFailWithError: %@", error);
}

-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations {
    NSLog(@"didUpdateToLocation: %@", [locations lastObject]);
    CLLocation *currentLocation = [locations lastObject];
    [locationManager stopUpdatingLocation];
}

ユーザーの位置情報を取得する方法の詳細については、このガイドを参照してください。このガイドを使用して、アプリに位置情報を実装しました: http://www.appcoda.com/how-to-get-current-location-iphone-user/

于 2013-07-30T20:27:04.673 に答える
0

これをどのようにテストしていますか?これをシミュレーターで実行している場合は、[Debug] -> [Location] -> [Freeway Drive] に移動できます。locationManager:didUpdateToLocation メソッドにブレーク ポイントを配置するか、ログ ステートメントを配置して現在の位置座標を記録することもできます。あなたはそれがうまくいくのを見るはずです。

于 2013-07-30T15:47:29.883 に答える