2011-04-29 29 views
0

這裏是我的代碼CLLocationManager不給我我的位置

CLLocationManager* locationManager = [[[CLLocationManager alloc]init]autorelease]; 
locationManager.delegate = self; 
locationManager.desiredAccuracy = kCLLocationAccuracyBest; 
locationManager.distanceFilter = kCLDistanceFilterNone; 
[locationManager startUpdatingLocation]; 


NSLog(@"Latitude :%f",locationManager.location.coordinate.latitude); 

CLLocation* currentLocation = [locationManager location]; 
_drivingReverseGeocoder = [[MKReverseGeocoder alloc] initWithCoordinate:[currentLocation coordinate]]; 
[_drivingReverseGeocoder setDelegate:self]; 
[_drivingReverseGeocoder start]; 

當我做我的NSLog我的長和LAT是0.000000。另外,我正在使用模擬器,但我期望我的長和緯度位於我當前位置所在的無限循環處。有沒有人有任何見解?

+0

你在使用'CLLocationManagerDelegate'嗎? – 2011-04-29 19:40:33

+0

是的,我是我沒有正確實施它?如果你使用模擬器,它總是對每個人說0.0? – nina 2011-04-29 20:39:51

回答

2

startUpdatingLocation後刪除所有組件並實現你的類,它是CLLocationManagerDelegate協議的一部分,這種方法:

- (空)的LocationManager:(CLLocationManager *)經理didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation { //使用newLocation here }

另外,在實際設備上測試。

+0

該方法永遠不會被調用,因爲我使用的是模擬器而不是移動。 – nina 2011-04-29 20:40:14

+0

是的,這就是您需要在設備上測試的原因。如果您還沒有設備,則可以使用FTLocationSimulator(https://github.com/futuretap/FTLocationSimulator)或類似解決方案來模擬更新。 – trydis 2011-04-30 07:03:06

相關問題