【问题标题】:An internal error occurred in the Places API libraryPlaces API 库中发生内部错误
【发布时间】:2016-10-13 10:34:24
【问题描述】:

我正在使用 GoogleMaps 和 GooglePlaces API,但我总是遇到同样的错误。

“操作无法完成。Places API 库中发生内部错误。如果您认为此错误代表错误,请使用我们社区和支持页面 (https://developers.google.com/places/support) 上的说明提交报告

我尝试运行 pod try GoogleMaps,当我启动项目时,任何地图都会被加载,只有一个带有不同选项的 tableView。

这是我的代码,我只想获取用户位置:

-(IBAction)getCurrentPlace:(UIButton *)sender {
[placesClient currentPlaceWithCallback:^(GMSPlaceLikelihoodList *placeLikelihoodList, NSError *error){
    if (error != nil) {
        NSLog(@"Pick Place error %@", [error localizedDescription]);
        return;
    }

    self.nameLabel.text = @"No current place";
    self.addressLabel.text = @"";

    if (placeLikelihoodList != nil) {
        GMSPlace *place = [[[placeLikelihoodList likelihoods] firstObject] place];
        if (place != nil) {
            self.nameLabel.text = place.name;
            self.addressLabel.text = [[place.formattedAddress componentsSeparatedByString:@", "]
                                      componentsJoinedByString:@"\n"];
        }
    }
}];
}

我在 didFinishLaunchingWithOptions 中导入了 mi APIKEY

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
[GMSServices provideAPIKey:@"MY_APIKEY"];

return YES;
}

这是我的 Podfile

platform :ios, '7.0'
source 'https://github.com/CocoaPods/Specs.git'

target ‘googlePlace’ do

   pod 'GoogleMaps'
   pod 'GooglePlaces'

end

最后,我的 apikey 在 Google Console 中配置为 iOS 应用程序。

有什么问题??

【问题讨论】:

    标签: google-maps maps cocoapods google-places-api google-places


    【解决方案1】:

    您的 API 密钥似乎无效或超出配额。

    您能否检查是否将正确的 API 密钥传递给 GMSPlacesClient.provideAPIKey(_:)。

    如果您确定您传递了正确的 API 密钥,请检查 Google API 控制台 (https://console.developers.google.com/) 以确保您没有超出每日配额限制。

    可以在此处跟踪此问题:https://issuetracker.google.com/issues/35830792

    【讨论】:

      【解决方案2】:

      回答我自己的问题

      https://developers.google.com/places/migrate-to-v2?hl=es-419

      这解决了问题

      迁移到 iOS 版 Google Places API 第 2 版

      随着 Google Maps SDK for iOS 第 2 版的发布,Google Places API for iOS 已从 Google Maps SDK for iOS 中分离出来,现在作为单独的 CocoaPod 分发。

      按照以下步骤更新您现有的应用:

      更新您的 Podfile 以引用 GooglePlaces CocoaPod 以及 GoogleMaps CocoaPod。如果您没有使用适用于 iOS 的 Google Maps SDK,您可以删除 GoogleMaps。

      如果您使用地点选择器,请更新您的 Podfile 以引用 GooglePlacePicker CocoaPod 以及 GooglePlaces。

      在您使用 Places API 的所有导入中将 GoogleMaps 重命名为 GooglePlaces。

      使用 GMSPlacesClient.provideAPIKey(:) 而不是 GMSServices.provideAPIKey(:) 指定您的 API 密钥。

      如果您使用的是 Google Maps SDK for iOS 或 Place Picker,请使用 GMSPlacesClient.openSourceLicenseInfo() 和 GMSServices.openSourceLicenseInfo() 获取所需的开源许可文本。

      【讨论】:

      • 我遇到了和你一样的问题,但我发现昨天我达到了我的请求限制,因为今天早上它运行良好。现在我又遇到了这个问题,但谷歌地图和谷歌地方都有新的 API 密钥。本质上,我正在尝试做与上述示例相同的事情:获取当前位置。更新我的 pod 对我不起作用,因为我已经将它们升级到不同的版本几次,但这个问题仍然存在。
      【解决方案3】:

      经过 8 到 12 小时的研发发现以下解决方案。我相信它会起作用的。

      只需在 AppDelegate.swift 文件中添加密钥,而不是任何其他类。它会解决你的问题。

         func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
               GMSPlacesClient.provideAPIKey("KEY")
               GMSServices.provideAPIKey("KEY")
      
          }
      

      注意:必须在AppDelegate中初始化GMSPlacesClient,因为初始化需要一些时间。

      【讨论】:

        【解决方案4】:

        2018 年的回答,在我的新工作中,我们很难解决这个问题。我自己的 Places 密钥有效,但我的新公司的 Places 密钥无效。几个小时后,我记得在设置自己的密钥时,我必须为 Places API 刷新或重新生成新密钥,然后才能让它工作。现在回到我现在的情况,我把这件事告诉了我的同事,然后繁荣,我们只需要刷新密钥,它就成功了! :)

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2015-09-21
          • 1970-01-01
          • 2016-07-08
          • 1970-01-01
          • 2018-10-31
          • 2017-06-24
          • 2018-11-30
          • 1970-01-01
          相关资源
          最近更新 更多