【问题标题】:How to Implement Google Places API For iOS?如何为 iOS 实现 Google Places API?
【发布时间】:2015-10-26 11:44:50
【问题描述】:

我想在文本字段上输入时实现(自动完成)谷歌建议的地方如何使用 api 键实现它?

为此,我已经下载了适用于 ios 1.9.1 的 google map sdk 并将 api 密钥放入 AppDelegate.m 但我能够获得以下代码 -

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

【问题讨论】:

    标签: iphone google-maps-sdk-ios


    【解决方案1】:

    -(void)textFieldDidBeginEditing:(UITextField *)textField 方法的 uitextfield 委托方法中,编写以下代码:-

    GMSPlacesClient *placesClient= [[GMSPlacesClient alloc] init];
    
    [placesClient autocompleteQuery:textField.text bounds:nil
                                                   filter:kGMSPlacesAutocompleteTypeFilterNoFilter
                                           callback:^(NSArray *results, NSError *error) {
                                               if (error != nil) {
                                                   NSLog(@"Autocomplete error %@", [error localizedDescription]);
                                                   return;
                                               }
    
                                               for (GMSAutocompletePrediction* result in results) {
    
                                                    NSLog(@"Result '%@' with placeID %@", result.attributedFullText.string, result.placeID);
                                               }
                                           }];
    

    【讨论】:

    • 你导入了GoogleMaps头文件了吗?
    猜你喜欢
    • 2011-11-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-10
    • 1970-01-01
    相关资源
    最近更新 更多