我所有我在我的应用程序中集成谷歌地图,我得到lat和很长的当前位置并尝试从那些lat和long获得地点标记但是当我使用地理编码时我的代码中出现了奇怪的错误。
-(void)viewDidload
{
_locationManager = [[CLLocationManager alloc] init];
_locationManager.desiredAccuracy = kCLLocationAccuracyBest;
_locationManager.delegate = self;
[self GetMyLocation];
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:0 longitude:0 zoom:16];
_mapView = [GMSMapView mapWithFrame:self.view.frame camera:camera];
_mapView.myLocationEnabled = YES;
[_mapView setMapType:kGMSTypeNormal];
[self.firstview addSubview:_mapView];
}
- (void) GetMyLocation{
_locationManager.delegate = self;
_locationManager.desiredAccuracy = kCLLocationAccuracyBest;
[_locationManager startUpdatingLocation];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
{
NSLog(@"My location %@", [locations lastObject]);
CLLocation *currentLocation = [locations lastObject];
[_mapView animateToLocation:currentLocation.coordinate];
CLGeocoder *geocoder = [[CLGeocoder alloc] init] ;
[geocoder reverseGeocodeLocation:self.locationManager.location
completionHandler:^(NSArray *placemarks, NSError *error) {
NSLog(@"reverseGeocodeLocation:completionHandler: Completion Handler called!");
if (error){
NSLog(@"Geocode failed with error: %@", error);
return;
}
if(placemarks && placemarks.count > 0)
{
//do something
CLPlacemark *topResult = [placemarks objectAtIndex:0];
NSString *addressTxt = [NSString stringWithFormat:@"%@ %@,%@ %@",
[topResult subThoroughfare],[topResult thoroughfare],
[topResult locality], [topResult administrativeArea]];
NSLog(@"%@",addressTxt);
}
}];
}
我在控制台区域出现此错误错误错误域= kCLErrorDomain代码= 8"(null)"
在控制台中出现此错误
2016-05-04 11:36:23.578 Juststart[2220:673181] ClientParametersRequest failed, 2 attempts remaining (0 vs 7). Error Domain=NSURLErrorDomain Code=-1001 " The request timed out." UserInfo={ NSErrorFailingURLStringKey=https://clients4.google.com/glm/mmap, _kCFStreamErrorCodeKey=-2102, NSErrorFailingURLKey=https://clients4.google.com/glm/mmap, NSLocalizedDescription=The request timed out., _kCFStreamErrorDomainKey=4, NSUnderlyingError=0x1478c690 {Error Domain=kCFErrorDomainCFNetwork Code=-1001 "(null)" UserInfo={_kCFStreamErrorDomainKey=4, _kCFStreamErrorCodeKey=-2102}}}
2016-05-04 11:36:32.653 Juststart [2220:673181] ClientParametersRequest失败,剩下7次尝试(0 vs 7)。错误域= NSURLErrorDomain代码= -1001"请求超时。" UserInfo = {NSErrorFailingURLStringKey = https://clients4.google.com/glm/mmap,_ kCFStreamErrorCodeKey = -2102,NSErrorFailingURLKey = https://clients4.google.com/glm/mmap,NSLocalizedDescription =请求超时。,_ kCFStreamErrorDomainKey = 4,NSUnderlyingError = 0x145c8610 {错误域= kCFErrorDomainCFNetwork代码= -1001&# 34;(NULL)" UserInfo = {_ kCFStreamErrorDomainKey = 4,_kCFStreamErrorCodeKey = -2102}}} 2016-05-04 11:36:48.671 Juststart [2220:673181] ClientParametersRequest失败,剩下6次尝试(0 vs 7)。错误域= NSURLErrorDomain代码= -1001"请求超时。" UserInfo = {NSErrorFailingURLStringKey = https://clients4.google.com/glm/mmap,_ kCFStreamErrorCodeKey = -2102,NSErrorFailingURLKey = https://clients4.google.com/glm/mmap,NSLocalizedDescription =请求超时。,_ kCFStreamErrorDomainKey = 4,NSUnderlyingError = 0x14551c30 {错误域= kCFErrorDomainCFNetwork代码= -1001&# 34;(NULL)" UserInfo = {_ kCFStreamErrorDomainKey = 4,_kCFStreamErrorCodeKey = -2102}}} 2016-05-04 11:37:05.707 Juststart [2220:673181] ClientParametersRequest失败,剩下5次尝试(0 vs 7)。错误域= NSURLErrorDomain代码= -1001"请求超时。" UserInfo = {NSErrorFailingURLStringKey = https://clients4.google.com/glm/mmap,_ kCFStreamErrorCodeKey = -2102,NSErrorFailingURLKey = https://clients4.google.com/glm/mmap,NSLocalizedDescription =请求超时。,_ kCFStreamErrorDomainKey = 4,NSUnderlyingError = 0x14586b90 {错误域= kCFErrorDomainCFNetwork代码= -1001&# 34; (空)" UserInfo = {_ kCFStreamErrorDomainKey = 4,_kCFStreamErrorCodeKey = -2102}}} 2016-05-04 11:37:10.712 Juststart [2220:673181] ClientParametersRequest失败,剩余1次尝试(0 vs 7)。错误域= NSURLErrorDomain代码= -1001"请求超时。" UserInfo = {NSErrorFailingURLStringKey = https://clients4.google.com/glm/mmap,_ kCFStreamErrorCodeKey = -2102,NSErrorFailingURLKey = https://clients4.google.com/glm/mmap,NSLocalizedDescription =请求超时。,_ kCFStreamErrorDomainKey = 4,NSUnderlyingError = 0x15f2cf50 {错误域= kCFErrorDomainCFNetwork代码= -1001&# 34; (空)" UserInfo = {_ kCFStreamErrorDomainKey = 4,_kCFStreamErrorCodeKey = -2102}}} 2016-05-04 11:37:25.237 Juststart [2220:673395] CFNetwork SSLHandshake失败(-9806)
答案 0 :(得分:1)
错误结果为
You get this error in case Apple's Geocoder knows nothing about provided address or geocoder is not able to find the location.
例如
CLGeocoder *geocoder = [[[CLGeocoder alloc] init] autorelease];
[geocoder reverseGeocodeLocation:self.locationManager.location
completionHandler:^(NSArray *placemarks, NSError *error) {
NSLog(@"reverseGeocodeLocation:completionHandler: Completion Handler called!");
if (error){
NSLog(@"Geocode failed with error: %@", error);
return;
}
if(placemarks && placemarks.count > 0)
{
//do something
CLPlacemark *topResult = [placemarks objectAtIndex:0];
NSString *addressTxt = [NSString stringWithFormat:@"%@ %@,%@ %@",
[topResult subThoroughfare],[topResult thoroughfare],
[topResult locality], [topResult administrativeArea]];
NSLog(@"%@",addressTxt);
}
}];
答案 1 :(得分:0)
在viewDidLoad中添加以下内容。
[_locationManager requestWhenInUseAuthorization];
[_locationManager requestAlwaysAuthorization];