2016-04-04 20 views
0

Ich erstelle eine App, die Google Place verwendet. Zuvor benutzte ich Yahoo's API und musste eine URL verwenden, die für die lokale Suche verantwortlich war, die von Yahoo bereitgestellt wurde. Die URL wurde folgende:Google Place api URL iOS

http://local.yahooapis.com/LocalSearchService/V3/localSearch?appid=SF0DVEvV34G4GnXEDU4SXniaDebJ_UvC1G1IuikVz3vpOJrBpyD.VqCJCVJHMh99He3iFz1Rzoqxb0b7Z.0-

Da nun yahoos api eingestellt ist, ich habe auf Google Platz wechseln entschieden. Ich kann jedoch keine URL finden. Ich downloade einfach das Framework und benutze den API-Schlüssel. Wo finde ich eine solche URL für Google Place?

Antwort

1

Register für die Google Places API durch die linke folgende unten angegeben:

https://code.google.com/apis/console

Siehe Code Verbindungs ​​für Orte Auto-Suche

https://github.com/AdamBCo/ABCGooglePlacesAutocomplete

NSString *const apiKey = @"*****23xAHRvnOf2BVG8o"; 
NSString * searchWord = @"search some place " 

NSString *urlString = [NSString stringWithFormat:@"https://maps.googleapis.com/maps/api/place/autocomplete/json?input=%@&types=establishment|geocode&radius=500&language=en&key=%@",searchWord,apiKey]; 

Pragma Marke - Netzwerk-Methoden

-(void)retrieveGooglePlaceInformation:(NSString *)searchWord withCompletion:(void (^)(BOOL isSuccess, NSError *error))completion { 

if (!searchWord) { 
    return; 
} 

searchWord = searchWord.lowercaseString; 

self.searchResults = [NSMutableArray array]; 

if ([self.searchResultsCache objectForKey:searchWord]) { 
    NSArray * pastResults = [self.searchResultsCache objectForKey:searchWord]; 
    self.searchResults = [NSMutableArray arrayWithArray:pastResults]; 
    completion(YES, nil); 

} else { 

    NSString *urlString = [NSString stringWithFormat:@"https://maps.googleapis.com/maps/api/place/autocomplete/json?input=%@&types=establishment|geocode&radius=500&language=en&key=%@",searchWord,apiKey]; 

    NSURL *url = [NSURL URLWithString:[urlString stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding]]; 
    NSURLSession *session = [NSURLSession sessionWithConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]]; 
    NSURLRequest *request = [NSURLRequest requestWithURL:url]; 
    NSURLSessionDataTask *task = [session dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) { 

     NSDictionary *jSONresult = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:nil]; 

     if (error || [jSONresult[@"status"] isEqualToString:@"NOT_FOUND"] || [jSONresult[@"status"] isEqualToString:@"REQUEST_DENIED"]){ 
      if (!error){ 
       NSDictionary *userInfo = @{@"error":jSONresult[@"status"]}; 
       NSError *newError = [NSError errorWithDomain:@"API Error" code:666 userInfo:userInfo]; 
       completion(NO, newError); 
       return; 
      } 
      completion(NO, error); 
      return; 
     } else { 

      NSArray *results = [jSONresult valueForKey:@"predictions"]; 

      for (NSDictionary *jsonDictionary in results) { 

      } 

      //[self.searchResultsCache setObject:self.searchResults forKey:searchWord]; 

      completion(YES, nil); 

     } 
    }]; 

    [task resume]; 
} 
} 
+0

Was ist searchWord Variable –

+0

Suche mit einem bestimmten Ort Namen nichts als geben Eingabe zu Google API zu Orten suchen – Sanju

+0

haben Sie herunterladen und sehen Sie den Code in diesem Link? https://github.com/AdamBCo/ABCGooglePlacesAutocomplete – Sanju

Verwandte Themen