2015-12-21 43 views
0

我現在被卡住了,我無法檢索到如何從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; 
} 

回答

0

您可以使用谷歌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; 

}

相關問題