如何在iOs中获取Google Place详细信息值

问题描述:

我现在被卡住了,我无法检索到如何从Google Place详细信息API的json下方获取值。如何在iOs中获取Google Place详细信息值

我想从“类型”节点获取所有数据。

{ 
    "address_components" =  (
       { 
      "long_name" = "Bridge Street"; 
      "short_name" = "Bridge St"; 
      types =    (
       route 
      ); 
     }, 
       { 
      "long_name" = London; 
      "short_name" = London; 
      types =    (
       locality, 
       political 
      ); 
     }, 
       { 
      "long_name" = London; 
      "short_name" = London; 
      types =    (
       "postal_town" 
      ); 
     }, 
       { 
      "long_name" = "Greater London"; 
      "short_name" = "Greater London"; 
      types =    (
       "administrative_area_level_2", 
       political 
      ); 
     }, 
       { 
      "long_name" = "United Kingdom"; 
      "short_name" = GB; 
      types =    (
       country, 
       political 
      ); 
     }, 
       { 
      "long_name" = "SW1A 2LW"; 
      "short_name" = "SW1A 2LW"; 
      types =    (
       "postal_code" 
      ); 
     } 
    ); 
    vicinity = London; 
} 

为什么不整合Google地方API本身而不是解析自己。

它的简单和方便地检索地方

这里是链接

https://developers.google.com/places/ios-api/

您可以使用谷歌Places API的。使用地点ID并使用以下代码获取地点详情值。

-(id)getAddressFromPlaceId:(NSString*)placeId 
{ 

NSString *placeRequest; 

if ([AppDelegate getInstance].isDetailsLimitReached) 
{ 
    placeRequest = [[NSString stringWithFormat:@"https://maps.googleapis.com/maps/api/place/details/json?placeid=%@&key=%@&language=en",placeId,[Utility getInstance].arrGooglkey[tempc]] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; 

} 
else 
{ 
    placeRequest = [[NSString stringWithFormat:@"https://maps.googleapis.com/maps/api/place/details/json?placeid=%@&language=en",placeId] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; 
} 

NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:placeRequest]cachePolicy:NSURLRequestUseProtocolCachePolicy 
            timeoutInterval:20.0]; 
NSError *error; 
NSData *response = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:&error]; 
if (error) 
{ 
    return nil; 
} 
else 
{ 
    NSDictionary *resData = [NSJSONSerialization JSONObjectWithData:response options:0 error:&error]; 
    if (error) 
    { 
     return nil; 
    } 
    else 
    { 
     if ([resData[@"status"] isEqualToString:@"OK"] || [[resData objectForKey:@"status"] isEqualToString:@"ZERO_RESULTS"]) { 

      return [resData[@"result"] mutableCopy]; 
     } 
     else 
     { 
      if ([AppDelegate getInstance].isDetailsLimitReached) 
      { 
       return nil; 
      } 
      [AppDelegate getInstance].isDetailsLimitReached = TRUE; 
      return [self getAddressFromPlaceId:placeId]; 
     } 
    } 

} 
return nil; 

}