如何从谷歌地图中的经纬度获取位置详细信息?

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 失败,剩余 7 次尝试(0 对 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=请求超时。, _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 失败,剩余 6 次尝试(0 对 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=请求超时。, _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 失败,剩余 5 次尝试(0 对 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 失败,剩余 1 次尝试(0 对 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=请求超时。, _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 失败 (-9806)

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.

例如

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

在您的 viewDidLoad 中添加以下内容。

[_locationManager requestWhenInUseAuthorization];
[_locationManager requestAlwaysAuthorization];