我在我的应用程序中运行以查找当前位置,但是第一次返回右转lat并且具有依赖的位置,但是当它们执行更新位置时,时间转到didFailWithError并返回 Domain = kCLErrorDomain Code = 0"(空)" 即可。我尝试了不同的不同解决方案,如
但没有一项工作
我的代码在这里:
- (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)"
答案 0 :(得分:0)
你好,伙计们,我找到了自己问题的解决方案。 我做了一些小错误。我每次都检查currentLocation!= nil,它是更新位置但当前位置Lat Long未设置。
//if (currentLocation != nil)
//{
self.lblLongitude.text = [NSString stringWithFormat:@"%.12f", currentLocation.coordinate.longitude];
self.lblLatitude.text = [NSString stringWithFormat:@"%.12f", currentLocation.coordinate.latitude];
//}
现在它正常运行。