2017-01-15 31 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