2012-03-14 6 views
2

이것은 내 다른 question과 관련이 있습니다. 그러나 문제는 네이티브 측에있을 수 있기 때문에 iOS 태그가있는 새 버전을 공개하고 있습니다.CLLocationManager가 위치를 업데이트하지 않습니다.

문제 : 위치 관리자가 위치를 업데이트하지 않습니다. 나는 locationManager.location 독서를 시도하고 항상 저에게 1 개의 캐시 된 위치를 준다.

그런 다음 코드를 수정하여 CLLocationManagerDelegate-(void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {} 을 호출하지 않습니다.

내 .H 파일 :

#import "TiModule.h" 
#import <CoreLocation/CoreLocation.h> 
#import <CoreMotion/CoreMotion.h> 

@interface TiMovementModule : TiModule<CLLocationManagerDelegate> 

@property (nonatomic, retain) CLLocationManager *locationManager; 
@property (nonatomic, readonly) NSDictionary *currentMovement; 

- (void)startMovementUpdates:(id)args; 
- (void)stopMovementUpdates:(id)args; 

@end 

하는 .m

/** 
* Your Copyright Here 
* 
* Appcelerator Titanium is Copyright (c) 2009-2010 by Appcelerator, Inc. 
* and licensed under the Apache Public License (version 2) 
*/ 
#import "TiMovementModule.h" 
#import "TiBase.h" 
#import "TiHost.h" 
#import "TiUtils.h" 

@interface TiMovementModule() 

@property (nonatomic, retain) CMMotionManager *motionManager; 

@end 

@implementation TiMovementModule 

@synthesize motionManager, locationManager; 

#pragma mark Internal 

// this is generated for your module, please do not change it 
-(id)moduleGUID 
{ 
    return @"3d2abdb6-bafb-451c-931d-a979dcc1ea78"; 
} 

// this is generated for your module, please do not change it 
-(NSString*)moduleId 
{ 
    return @"ti.movement"; 
} 

#pragma mark Lifecycle 

-(void)startup 
{ 
    // this method is called when the module is first loaded 
    // you *must* call the superclass 
    [super startup]; 

    self.locationManager = [[CLLocationManager alloc] init]; 
    self.locationManager.delegate = self; 
    self.locationManager.distanceFilter = kCLDistanceFilterNone; 
    self.locationManager.desiredAccuracy = kCLLocationAccuracyBestForNavigation; 

    motionManager = [[CMMotionManager alloc] init]; 

    NSLog(@"[INFO] %@ loaded",self); //this prints 
} 

-(void)shutdown:(id)sender 
{ 
    // this method is called when the module is being unloaded 
    // typically this is during shutdown. make sure you don't do too 
    // much processing here or the app will be quit forceably 

    // you *must* call the superclass 
    [super shutdown:sender]; 
} 

#pragma mark Cleanup 

-(void)dealloc 
{ 
    self.motionManager = nil; 
    self.locationManager = nil; 

    [super dealloc]; 
} 

#pragma Public APIs 

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

    NSLog(@"I AM HEREEEEEE!!!!!!!"); //this never prints 

} 

- (void)startMovementUpdates:(id)args 
{ 
    NSLog(@"[INFO] starting updates..."); 

    [self.locationManager startUpdatingLocation]; 
    [motionManager startDeviceMotionUpdatesUsingReferenceFrame:CMAttitudeReferenceFrameXTrueNorthZVertical]; 
    NSLog(@"[INFO] started updates."); //this prints 
} 

- (void)stopMovementUpdates:(id)args 
{ 
    [locationManager stopUpdatingLocation]; 
    [motionManager stopDeviceMotionUpdates]; 
} 

- (id)currentMovement 
{ 
    NSDictionary *location = [NSDictionary dictionaryWithObjectsAndKeys: 
           [NSNumber numberWithDouble:locationManager.location.coordinate.longitude], @"longitude", 
           [NSNumber numberWithDouble:locationManager.location.coordinate.latitude], @"latitude", 
           [NSNumber numberWithDouble:locationManager.location.altitude], @"altitude", 
           nil]; 

    NSDictionary *rotation = [NSDictionary dictionaryWithObjectsAndKeys: 
           [NSNumber numberWithDouble:motionManager.deviceMotion.attitude.roll], @"roll", 
           [NSNumber numberWithDouble:motionManager.deviceMotion.attitude.pitch], @"pitch", 
           [NSNumber numberWithDouble:motionManager.deviceMotion.attitude.yaw], @"yaw", 
           nil]; 


    NSDictionary *movementData = [NSDictionary dictionaryWithObjectsAndKeys: 
            location, @"location", 
            rotation, @"rotation", 
            nil]; 
    return movementData; // here I pull location and it always gives me cached location. 
} 

@end 

답변

1

답변은 위치 업데이트가 주 스레드에서 수행되어야한다는 것입니다. 티타늄에서는 함수 시작 부분에서 ENSURE_UI_THREAD를 호출하면됩니다.

1

당신이 줄에 중단 점을 넣어 시도해야합니다 : 혹시이 같은 얻는 경우에

[self.locationManager startUpdatingLocation]; 

보고 코드에서 실행 된 적이 있다는 증거는 없습니다.

관련 문제