2015-06-02 4 views
2

В настоящее время мы можем использовать reverseGeocodeCoordinate от GeoCoder, чтобы перевернуть lat до адреса.Google iOS Geocoding SDK reverse lat long to Places ID

https://developers.google.com/maps/documentation/ios/reference/interface_g_m_s_geocoder

Тем не менее, кажется, не имеет возможности полностью изменить его к местам Google.

Возможно ли получить места от SDK iOS?

Благодаря Alex

ответ

0

Да, вы можете использовать CLGeocoder ИО SDK. Проверьте код,

+ (void)fetchAddressFromCoordinates:(CoordinatesDataModel *)coordinates returnValue:(void(^)(NSString* address))returnBlock { 

CLLocation *currentLocation = [[CLLocation alloc] initWithLatitude:(CLLocationDegrees)[coordinateDataModel.latitude doubleValue] longitude:(CLLocationDegrees)[coordinateDataModel.longitude doubleValue]];  
if (currentLocation != nil) 
// Reverse Geocoding 
// “reverseGeocodeLocation” method to translate the locate data into a human-readable address.  
// The reason for using "completionHandler" ---- 
// Instead of using delegate to provide feedback, the CLGeocoder uses “block” to deal with the response. By using block, you do not need to write a separate method. Just provide the code inline to execute after the geocoding call completes. 
CLGeocoder *geocoder = [[CLGeocoder alloc] init]; 
[geocoder reverseGeocodeLocation:currentLocation completionHandler:^(NSArray *placemarks, NSError *error) 
{ 
    if (error == nil && [placemarks count] > 0) 
    { 
     if(placemarks && placemarks.count > 0) 
     { 
      CLPlacemark *placemark= [placemarks objectAtIndex:0]; 
      // address defined in .h file 
      NSString *address = [NSString stringWithFormat:@"%@ %@ %@ %@ %@",[placemark subThoroughfare], [placemark thoroughfare], [placemark locality], [placemark administrativeArea], [placemark country]]; 

      NSCharacterSet *whitespace = [NSCharacterSet whitespaceCharacterSet]; 
      address = [address stringByTrimmingCharactersInSet:whitespace]; 

      NSMutableArray *words = [[address componentsSeparatedByCharactersInSet:whitespace] mutableCopy]; 
      //   NSLog(@":%@",words); 
      NSMutableArray * wordsArray = [[NSMutableArray alloc] init]; 
      for (int i= 0; i< [words count]; i++) { 
       if (![[words objectAtIndex:i] isEqualToString:@"(null)"]) { 
        [wordsArray addObject:[words objectAtIndex:i]]; 
       } 
      } 
      address = [wordsArray componentsJoinedByString:@" "]; 
      returnBlock(address); 
     } 
    } 
}];} 
+0

Спасибо, но можно ли использовать Google Адреса? –

+0

Проверьте [это] (http://stackoverflow.com/questions/24503375/get-latitude-and-longitude-based-on-address-using-geocoder-class-in-ios). – Paddy

+0

Спасибо, проверено. поэтому вы имеете в виду, что мне нужно сначала получить адрес, а другой запрос - получить данные в Google. –

Смежные вопросы