地方选择器无法加载

时间:2019-05-16 10:14:08

标签: ios google-places-api

当我加载位置选择器时,它最初会加载,但后来我无法选择任何地方,因为它会关闭

    func placePicker(_ viewController: GMSPlacePickerViewController, didPick place: GMSPlace) {
    print("Place name \(place.name)")
    print("Place address \(place.formattedAddress)")
    print("Place attributions \(place.attributions)")
    viewController.dismiss(animated: true, completion: nil)

}
func placePickerDidCancel(_ viewController: GMSPlacePickerViewController) {
    // Dismiss the place picker, as it cannot dismiss itself.
    viewController.dismiss(animated: true, completion: nil)

    print("No place selected")
}

enter image description here

1 个答案:

答案 0 :(得分:0)

几个月前它很容易,可以通过修复,

API密钥与Google Maps APIKey相同

如果它不能解决您的解决方案,那么您会发现一些类似here

的内容

首先,转到https://console.developers.google.com/apis/并确保已启用Google Places API。在左上方选择您的项目,然后在左侧也选择库。然后,查找“ Places API”并启用该API。

enter image description here

enter image description here

第二,请确保您已启用计费帐户。为此,请转到https://console.developers.google.com/billing/并继续创建一个帐户。确保您的项目也已与此帐户关联。要关联该帐户,请转到您的项目,然后从左上角的汉堡菜单中选择“结算”选项。

最后,如果您有应用程序限制,请确保iOS项目中的捆绑包标识符与您正在使用的API密钥相关联。在XCode中转到您的项目,单击“常规”选项卡,然后按“捆绑标识符”复制值。然后,返回到https://console.developers.google.com/apis/并确保已选择您的项目。然后,转到左侧的“凭据”标签。选择您的密钥,然后转到显示以下位置的位置:使用这些捆绑包标识符之一接受来自iOS应用程序的请求,然后将该值粘贴到下面的文本框中。

如果您有API限制,请确保Places API已添加到您可访问的API列表中。

单击顶部的“重新生成密钥”,然后使用在项目中显示“ API密钥”的位置下生成的新密钥。此过程最多可能需要5分钟才能生效。

enter image description here enter image description here