【发布时间】: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