2017-01-15 13 views
-2

我想在模擬器中獲取我的位置。幾次它的工作,但...現在我總是得到0.000000作爲我的位置。這裏是我使用的代碼:客觀c找出我的位置?

#import <CoreLocation/CoreLocation.h> 

CLLocationManager *locationManager = [[CLLocationManager alloc] init]; 
[locationManager startUpdatingLocation]; 
CLLocation *location = [locationManager location]; 
CLLocationCoordinate2D coordinate = [location coordinate]; 
NSLog(@"%f",location.coordinate.latitude); 
NSLog(@"%f",location.coordinate.longitude); 

運行應用程序,我在模擬器調試改變後 - >位置 - >自定義位置...是否有人可以解釋爲什麼它停止工作?

+0

你的委託方法在哪裏? – matt

回答

1

這不會有任何效果,除非是意外:

當你調用startUpdatingLocation委託消息(假設你有一個位置管理代表,你應該總是) - 尤其是,locationManager:didUpdateLocations:是您收到有關您所在位置信息的地方。

+0

請參閱我的討論和示例:http://www.apeth.com/iOSBook/ch35.html#_location – matt

+0

好吧,我明白了。現在如何從「位置」獲得只有緯度和長度的NSArray在didUpdateLocations方法中 –

+0

嗯,想一想。 'didUpdateLocations'中的什麼_位置?它是一個CLLocation數組。那麼如何從一個CLLocation數組中獲得一個CLLocation?你如何從一個CLLocation獲取經度和緯度? – matt