在模拟器中更新位置,但在设备中没有

时间:2015-02-02 13:55:52

标签: ios gps cllocationmanager

我试图通过使用核心位置框架来获取用户的更新位置。它在模拟器中工作,但不在ipad / iphone中。我使用以下代码来获取它。在模拟器中,我正在使用高速公路驱动器。

-(void)locationManager:(CLLocationManager *)manager didUpdateToLocation: 
(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{

 CLLocation *currentLocation=newLocation;
 NSLog(@"location : %@",currentLocation);

if(currentLocation !=nil)
{
 self.latitudelabel.text = [NSString 
 stringWithFormat:@"%.8f",currentLocation.coordinate.latitude];
 self.longitudelabel.text = [NSString  
 stringWithFormat:@"%.8f",currentLocation.coordinate.longitude];
}

CLLocationDistance distance = [newLocation distanceFromLocation:oldLocation];

NSLog(@"Calc.distance%f",distance);

[geocoder reverseGeocodeLocation:currentLocation completionHandler:^
(NSArray   *placemarks, NSError *error)
{

 if(error == nil && [placemarks count]>0)
 {
     placemark = [placemarks lastObject];
     NSLog(@"Country %@",placemark.country);
     NSLog(@"Area %@",placemark.administrativeArea);
     NSLog(@"City %@",placemark.locality);
     NSLog(@"Code %@",placemark.postalCode);
     NSLog(@"Road %@",placemark.thoroughfare);
     NSLog(@"Number %@",placemark.subThoroughfare);

     self.addresslabel.text = [NSString stringWithFormat:@"%@ %@ 
\n %@ %@    \n %@ \n %@",
 placemark.subThoroughfare,    placemark.thoroughfare,
                          placemark.postalCode, placemark.locality,
                          placemark.administrativeArea,
                          placemark.country];

 }
 else
 {
     NSLog(@"tktk%@",error.debugDescription);

 }
}];

}

1 个答案:

答案 0 :(得分:0)

进入settings > Privacy > Location services > Your app > Always.

您还可以查看以下问题Core Location not working in iOS 8

中发布的其他替代方案