【问题标题】:Google Places iOS - Can't load search resultGoogle Places iOS - 无法加载搜索结果
【发布时间】:2018-02-01 22:59:49
【问题描述】:

我在我的 iOS 项目中使用来自 Google Places API 的 GMSAutoCompleteViewController。

今天突然我的 GMSAutoCompleteViewController 不断给我错误“无法加载搜索结果”。

我已使用新的 API 密钥重新生成了我的 API 密钥。我已经尝试了一切,但仍然有一些它不起作用。

我正在使用 Objective-C。有人可以帮忙吗?

代码

GMSAutocompleteViewController *acController = [[GMSAutocompleteViewController alloc] init];
    acController.delegate = self;
[self.navigationController pushViewController:acController animated:YES];

委托方法

- (void)viewController:(GMSAutocompleteViewController *)viewController
                didAutocompleteWithPlace:(GMSPlace *)place {
    // Do something with the selected place.
    NSLog(@"Place name %@", place.name);
    NSLog(@"Place address %@", place.formattedAddress);
    NSLog(@"Place attributions %@", place.attributions.string);
    NSLog(@"Latitude = %.20f",place.coordinate.latitude);
    NSLog(@"Longitude = %.20f",place.coordinate.longitude);
    NSLog(@"Type = %@",place.types);
    NSLog(@"Place ID = %@",place.placeID);
    //[self dismissViewControllerAnimated:YES completion:nil];
    [self.navigationController popViewControllerAnimated:YES];

    /* Call and API in background to get the address according to the new LAT AND LONG as well
     Once get the address from there we can store the latitude and longitude in the cache
     if type of search is Postal code then we have to call another web service i.e. FIND ADDRESS to get the whole exact address */

    [self callWS_ConvertLatLongWithLatitude:[NSString stringWithFormat:@"%.20f",place.coordinate.latitude]
                               andLongitude:[NSString stringWithFormat:@"%.20f",place.coordinate.longitude]
                               inBackground:NO];

}

- (void)viewController:(GMSAutocompleteViewController *)viewController
didFailAutocompleteWithError:(NSError *)error {

    NSLog(@"error: %ld", [error code]);

    [self.navigationController popViewControllerAnimated:YES];

}

// User canceled the operation.
- (void)wasCancelled:(GMSAutocompleteViewController *)viewController {
    NSLog(@"Autocomplete was cancelled.");

    [self.navigationController popViewControllerAnimated:YES];
}

// Turn the network activity indicator on and off again.
- (void)didRequestAutocompletePredictions:(GMSAutocompleteViewController *)viewController {
    [UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
}

- (void)didUpdateAutocompletePredictions:(GMSAutocompleteViewController *)viewController {
    [UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
}

【问题讨论】:

  • 在您获得搜索结果之前或开始时您会收到此错误?你有没有在 didFinishLaunchingWithOptions 中设置 GMSPlacesClient.provideAPIKey("API_KEY_HERE")
  • 直到昨天我才能够得到搜索结果。今天突然出现错误。
  • 如果我继续按“再试一次”,它会显示一些结果列表,我从那里选择一个结果,然后再次显示“无法加载搜索结果”
  • 我相信您遇到了此处报告的问题:issuetracker.google.com/issues/64280749
  • 没错,这是同一个问题。我还在谷歌问题跟踪器上报告了它。感谢上帝,它现在解决了。 :-)

标签: ios google-maps google-places-api gmsautocomplete


【解决方案1】:

确保已启用适用于 IOS 的 Google Places API。

  1. 转到您的https://console.developers.google.com/apis/
  2. 选择“图书馆”-“Google Places API for iOS”
  3. 启用(蓝色按钮)

API Key与谷歌地图APIKey相同

【讨论】:

  • 它已经启用,有时它返回数据,但大多数时候没有数据
  • 面临同样的问题。它在 10 次中工作一次。无法理解问题。
  • 有人找到解决这个问题的不同方法吗?
【解决方案2】:

2018 年 6 月 18 日之后,google 限制了限额并更改了政策,您需要启用 billing 之后才能工作。

我已经启用了 google places api 和 google map api,但它仍然显示错误。

启用结算后解决

【讨论】:

  • 任何参考文件?
【解决方案3】:

我遇到了同样的问题。当我返回并再次检查计费帐户页面时,我注意到它没有列出我当前的工作项目名称。 一旦我添加了我当前的项目,它就起作用了。

确保您当前的项目列在结算页面中

【讨论】:

    【解决方案4】:

    -> 确保更新到最新版本的 Google Places Pod(GooglePlacepicker 已弃用)

    -> 启用 Google Places API

    -> 还要检查 APIKey 是否正确

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-01-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-08-05
      相关资源
      最近更新 更多