2011-10-15 40 views

回答

2

那是不可能的。原因很简单,该设备没有定位,可以随时匹配您所需的精度。它可能不得不打开GPS芯片来做到这一点,这也需要一些时间来创建一个位置(没有额外的信息和过时的年历,在最坏的情况下这可能需要长达15分钟)。

0

以这种方式调整CLLocationManger是不可能的。然而,你可以做的是围绕CLLocationManager编写一个包装器,它在启动时获得当前位置,并在你每次请求时返回它。但是,可能存在位置尚未(可用)的情况,并且随着您始终使用GPS设备,此方法非常耗电。

0

这是到目前为止还没有在最佳方式(甚至不是一个很好的大概样子)使用CLLocationManager,当我发现我上回去和改变我的代码只有一个CLLocationManager内规划的时候我AppDelegate并让所有的子视图控制器调用AppDelegate以获取其位置需求。

我在视图控制器(不是主控制器或应用程序委托)中有以下代码,并且在视图控制器被我的主视图导航控制器按下后约5-10秒,它开始用NSLog精准的长/纬度我的位置(即委托locationManager:didUpdateToLocation:fromLocation:开始被称为法):

- (void)viewDidLoad { 
    [super viewDidLoad]; 
    // .... 
    self.locationManager = [[[CLLocationManager alloc] init] autorelease]; 
    [locationManager setDelegate:self]; 
    [locationManager setDesiredAccuracy:kCLLocationAccuracyBest]; 
    [locationManager setDistanceFilter:kCLDistanceFilterNone]; 
    [locationManager startUpdatingLocation]; 
    // .... 
} 

// This will be called just a few seconds after the view appears and the 
// location is accurate (if I have location services on and good sky-line of sight) 
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation { 
    NSDate* eventDate = newLocation.timestamp; 
    NSTimeInterval howRecent = [eventDate timeIntervalSinceNow]; 
    if (abs(howRecent) < 5.0) { 
     self.latitude = [NSNumber numberWithDouble:newLocation.coordinate.latitude]; 
     self.longitude = [NSNumber numberWithDouble:newLocation.coordinate.longitude]; 
     NSLog(@"New Latitude %+.6f, Longitude %+.6f", newLocation.coordinate.latitude, newLocation.coordinate.longitude); 
    } 
} 

// Then, tear down the location Manager (so I can use it in another view controller) 
// A bit excessive possibly, but I like to be absolutely sure that my App does not use the GPS 
// when it doesn't need it to save batter life. 
- (void)viewWillDisappear:(BOOL)animated { 
    [super viewWillDisappear:animated]; 
    [locationManager stopMonitoringSignificantLocationChanges]; 
    [locationManager stopUpdatingHeading]; 
    [locationManager stopUpdatingLocation]; 
} 

- (void)viewDidDisappear:(BOOL)animated { 
    [super viewDidDisappear:animated]; 
    [locationManager stopMonitoringSignificantLocationChanges]; 
    [locationManager stopUpdatingHeading]; 
    [locationManager stopUpdatingLocation]; 
} 

- (void)viewDidUnload { 
    [locationManager stopUpdatingLocation]; 
    [locationManager stopMonitoringSignificantLocationChanges]; 
    [locationManager stopUpdatingHeading]; 
    [locationManager setDelegate:nil]; 
    self.locationManager = nil; 
} 

- (void)dealloc { 
    // .... 
    [locationManager stopUpdatingLocation]; 
    [locationManager setDelegate:nil]; 
    [locationManager release], locationManager = nil; 
    // .... 
    [super dealloc]; 
} 

然后,像actionSheet:clickedButtonAtIndex:的地方,我能得到的位置值on0demandlocationManager.location.coordinate.latitude/locationManager.location.coordinate.longitudeself.latitude/self.longitude