我有一個關於位置的問題。獲取有關didUpdateLocations和didUpdateToLocation的位置永遠不會調用ios 5.1和ios6
我需要在iOS 5.1和iOS 6上獲取經度和緯度的位置。
但我在didUpdateLocations和didUpdateToLocation函數中編寫NSLog。
我沒有看到控制檯中的日誌顯示。
我使用模擬設置位置。我測試的緯度值是25.317973,經度值是121.538161(D1)。
那麼我的測試值是(25.917973,121.538161)(D2)。
D1和D2的距離大於10米;
但我從來沒有在控制檯中看到日誌顯示。
我在下方附上我的代碼:
我.h文件中
#mport <GoogleMaps/GoogleMaps.h>
#import <CoreLocation/CoreLocation.h>
#import <Corelocation/CLLocationManagerDelegate.h>
@interface LocationMapViewController : AbstractViewController< CLLocationManagerDelegate, GMSMapViewDelegate >
@property (strong, nonatomic) CLLocationManager *locationManager;
@end
我.m文件
- (void)viewDidLoad
{
[super viewDidLoad];
if(_locationManager == nil)
{
_locationManager = [CLLocationManager new];
_locationManager.delegate = self;
_locationManager.desiredAccuracy = kCLLocationAccuracyBest;
_locationManager.distanceFilter = 10.0f;
[_locationManager startUpdatingHeading];
}
-(void) locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
{
NSLog(@"==latitude %f, longitude %f", [[locations objectAtIndex:([locations count]-1)] coordinate].latitude , [[locations objectAtIndex:([locations count]-1)] coordinate].longitude);
}
-(void) locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
NSLog(@"====latitude %f, longitude %f", newLocation.coordinate.latitude, newLocation.coordinate.longitude);
}
有任何人知道什麼是錯我的代碼?
非常感謝你
我曾試過你的方法。但我仍然沒有在我的控制檯中獲得任何日誌。 :( 我曾嘗試在距離設置差異。 我不知道什麼問題導致。 我曾經使用谷歌地圖api,所以我導入這個頭文件。 謝謝 – dickfala
我明白我的錯在哪裏。 因爲我沒有將startUpdatingHeading更改爲startUpdatingLocation。 非常感謝faterpig。 – dickfala
是的,我正要回答這個問題。祝您好運! :) – faterpig