Search code examples
iosobjective-cgoogle-maps-sdk-iosgeocode

How to get location details from latitude and longitude in googlemaps,?


HI all i integrated google map in my applications, i am getting lat and long of current location and try to get place mark from those lat and long but i get strange error in my code when i used geocode.

 -(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);
                   }
               }];




   }

I get this error in my console area Error Error Domain=kCLErrorDomain Code=8 "(null)"

get this error in console

                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 failed, 7 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=0x145c8610 {Error Domain=kCFErrorDomainCFNetwork Code=-1001 "(null)" UserInfo={_kCFStreamErrorDomainKey=4, _kCFStreamErrorCodeKey=-2102}}} 2016-05-04 11:36:48.671 Juststart[2220:673181] ClientParametersRequest failed, 6 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=0x14551c30 {Error Domain=kCFErrorDomainCFNetwork Code=-1001 "(null)" UserInfo={_kCFStreamErrorDomainKey=4, _kCFStreamErrorCodeKey=-2102}}} 2016-05-04 11:37:05.707 Juststart[2220:673181] ClientParametersRequest failed, 5 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=0x14586b90 {Error Domain=kCFErrorDomainCFNetwork Code=-1001 " (null)" UserInfo={_kCFStreamErrorDomainKey=4, _kCFStreamErrorCodeKey=-2102}}} 2016-05-04 11:37:10.712 Juststart[2220:673181] ClientParametersRequest failed, 1 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=0x15f2cf50 {Error Domain=kCFErrorDomainCFNetwork Code=-1001 " (null)" UserInfo={_kCFStreamErrorDomainKey=4, _kCFStreamErrorCodeKey=-2102}}} 2016-05-04 11:37:25.237 Juststart[2220:673395] CFNetwork SSLHandshake failed (-9806)


Solution

  • the error result as You get this error in case Apple's Geocoder knows nothing about provided address or geocoder is not able to find the location.

    for example

    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);
       }
        }];