【问题标题】:location updating in simulator but not in device在模拟器中而不是在设备中更新位置
【发布时间】:2015-02-02 13:55:51
【问题描述】:

我正在尝试通过使用核心位置框架来获取用户的更新位置。它在模拟器中工作,但在 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);

 }
}];

}

【问题讨论】:

  • 你有什么设备?设备中的 iOS 版本是什么? iOS 8?
  • 我有 iPad,版本是 iOS 8.1

标签: ios gps cllocationmanager


【解决方案1】:

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

您还可以查看以下问题Core Location not working in iOS 8中发布的其他替代方法

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-08-14
    • 1970-01-01
    • 1970-01-01
    • 2015-12-20
    • 2012-07-09
    • 1970-01-01
    • 2011-01-04
    相关资源
    最近更新 更多