Google 地点 api URL iOS

Google Place api URL iOS

我正在创建一个使用 Google Place 的应用程序。在我以前使用 Yahoo 的 api 并且不得不使用由 yahoo 提供的负责本地搜索的 url 之前。 url 如下:

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

自从雅虎的 api 停产后,我决定切换到 Google 地方。但是我找不到要使用的 Url。我只是下载框架并使用 api 键。哪里可以找到这样的 url for Google 地方。

通过下面提供的链接注册 Google 个地点 API:

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

参考代码 Link 以获取地点自动搜索

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 mark - 网络方法

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