【发布时间】:2016-10-14 23:16:12
【问题描述】:
我在我的应用程序中运行以查找当前位置,但第一次返回正确的纬度,有依赖的位置,但是当他们 didUpdateLocations 时,时间转到 didFailWithError 并返回 Domain=kCLErrorDomain Code=0 "(null)" 。我尝试了不同的不同解决方案,例如
- 重置内容和设置
- 在 Xcode 中,产品 -> 方案 -> 编辑 方案,然后取消“允许位置模拟器”并到iOS 模拟器和重置内容和设置并再次到 Xcode,重复第一步。然后到iOS模拟器并重置。
但这些都不起作用
我的代码在这里:
- (void)locationManager:(CLLocationManager *)manager
didUpdateLocations:(NSArray *)locations{
NSLog(@"didUpdateToLocation: %@", [locations lastObject]);
CLLocation *currentLocation = [locations lastObject];
if (currentLocation != nil)
{
self.lblLongitude.text = [NSString stringWithFormat:@"%.12f", currentLocation.coordinate.longitude];
self.lblLatitude.text = [NSString stringWithFormat:@"%.12f", currentLocation.coordinate.latitude];
}
NSLog(@"Resolving the Address");
[geocoder reverseGeocodeLocation:currentLocation completionHandler:^(NSArray *placemarks, NSError *error) {
NSLog(@"Found placemarks: %@, error: %@", placemarks, error);
if (error == nil && [placemarks count] > 0) {
placemark = [placemarks lastObject];
NSString *geoMapItem = placemark.description;
NSRange start = [geoMapItem rangeOfString:@"dependentLocality"];
NSRange end = [geoMapItem rangeOfString:@")" options:NSCaseInsensitiveSearch range:NSMakeRange(start.location, 1000)];
NSString *dataString = [geoMapItem substringWithRange:NSMakeRange(start.location, end.location - start.location + end.length)];
dataString = [dataString stringByReplacingOccurrencesOfString:@"\n" withString:@""];
dataString = [dataString stringByReplacingOccurrencesOfString:@" " withString:@""];
dataString = [dataString stringByReplacingOccurrencesOfString:@"\"" withString:@""];
start = [dataString rangeOfString:@"("];
end = [dataString rangeOfString:@")"];
NSLog(@"datastring===>%@",dataString);
lblAddress.text = [NSString stringWithFormat:@"%@ \n%@ %@\n%@\n%@",
dataString,
placemark.postalCode, placemark.locality,
placemark.administrativeArea,
placemark.country];
} else
{
NSLog(@"%@", error.debugDescription);
}
} ];}
更新位置后第一次进入错误块
-(void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error{
NSLog(@"didFailWithError%@",error);
UIAlertView *errorAlert = [[UIAlertView alloc]
initWithTitle:@"Error" message:@"Failed to Get Your Location" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[errorAlert show];}
并得到这个错误 didFailWithErrorError Domain=kCLErrorDomain Code=0 "(null)"
【问题讨论】:
-
你是在模拟器上运行的吗?
-
你查看了这个答案吗? stackoverflow.com/questions/1409141/…
-
不,我正在 ipad、iphone5s、iphone6 上尝试。
-
@Dominic 我看到了你的建议,但我不满意你能不能给我提供更多..
-
@Vishnugondlekar 我在尝试不同的 ios 设备,但没有任何改变
标签: ios objective-c iphone ios7 ios5