2016-08-02 136 views
1

我遵循了许多教程,但都没有工作。坐标始终输出0.000000,0.000000。目标c GPS坐标不起作用

这里是我的位置代码:

- (void)locationManager:(CLLocationManager *)manager 
    didUpdateLocations:(NSArray *)locations 
{ 
    currentLocation = (CLLocation *)[locations lastObject]; 

} 
-(void)getLocation { 
    longitude = floorf(currentLocation.coordinate.longitude * 10000)/10000; 

} 

我有这样的一个按钮:

locationManager stopUpdatingLocation]; 
[self getLocation]; 

而且我有这个在viewDidLoad中:

locationManager = [[CLLocationManager alloc] init]; 
locationManager.delegate = self; 
[locationManager startUpdatingLocation]; 

我在xcode的ios模拟器中使用假的位置,所以它不应该输出0.000000。

回答

0

您需要请求授权才能使用位置服务。

if([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0) { 
    [self.locationManager requestAlwaysAuthorization]; 
} 
0

您可能需要在viewDidLoad中添加此行:

[locationManager requestAlwaysAuthorization]; 

如果不工作,我倾向于说这是因为你在模拟器中运行。即使是假的地点也让我一度陷入困境。你可以在设备上运行吗?

编辑:尝试添加这Info.plist中:

<key>NSLocationAlwaysUsageDescription</key> 
<string>This application requires location services to work</string> 
+0

我现在无法在设备上运行。但我会给这个镜头。 –

+0

雅没有工作。它没有显示授权弹出。 –

+0

见编辑@GeorgeYoung –