ios5 - CLLocationManager 未更新位置

标签 ios5 gps titanium core-location cllocationmanager

这与我的另一个question有关但我打开一个带有 iOS 标签的新标签只是因为问题可能出在 native 端。

问题:位置管理器未更新位置。我尝试阅读 locationManager.location,它总是为我提供一个缓存位置。

然后我修改了代码以使用 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

最佳答案

您应该尝试在此行上放置断点:

[self.locationManager startUpdatingLocation];

看看你是否能到达那里,因为你的代码没有证据表明它曾经被执行过。

关于ios5 - CLLocationManager 未更新位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9694269/

相关文章:

iphone - iOS - 在 iphone 5 分辨率上支持 xib

javascript - 为什么我的 iPhone Web 应用程序中两次被要求使用 GPS

javascript - 如何将一行附加到 Titanium 中的 TableViewSection?

javascript - 为什么 Titanium 不接受日期作为 SQLite 中的列类型?

Android 平板电脑 API 和 Android 手机 API

ios - 更改 UINavigation Controller 以与 SlidePanel 配合使用

iphone - 如何保存来自不同 View Controller 的数据并将其加载到 iOS 中的另一个 View Controller 中

android - 如何在 Android 和 IOS 中创建基本的 Google Glass 应用程序

node.js - 我如何将 GPS 数据发送到 parrot ar 无人机并转到我的无人机的 GPS 位置?

java - 如何将我的位置(经度和纬度)作为回复短信发送给其他人?