You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

iOS应用调用Google Places Autocomplete API遇Error Code -2错误求助

iOS中使用Google Places API获取地点自动补全建议时的403错误问题

我在iOS应用中使用Google Places API获取特定地理区域内的餐厅地点自动补全建议,但遇到了无法解决的错误。以下是我使用的代码:

func searchPlaces(query: String) {
    guard !query.isEmpty else {
        self.querylocations = []
        return
    }

    let token = GMSAutocompleteSessionToken()

    let northWestBounds = CLLocationCoordinate2DMake(40.921628, -73.700051)
    let southEastBounds = CLLocationCoordinate2DMake(40.477398, -74.259087)

    let filter = GMSAutocompleteFilter()
    filter.types = [kGMSPlaceTypeRestaurant]
    filter.locationBias = GMSPlaceRectangularLocationOption(northWestBounds, southEastBounds)

    let request = GMSAutocompleteRequest(query: query)
    request.filter = filter
    request.sessionToken = token

    GMSPlacesClient.shared().fetchAutocompleteSuggestions(from: request, callback: { ( results, error ) in
        if let error = error {
            print("Autocomplete error: \(error)")
            return
        }
        if let autocompleteResults = results {
            for result in autocompleteResults {
                if let place = result.placeSuggestion {
                    self.querylocations.append(Place(name: place.attributedFullText.string,
                                                     coordinate: CLLocationCoordinate2D(),
                                                     id: place.placeID))
                }
            }
        }
    })
}

遇到的错误如下:

Autocomplete error: Error Domain=com.google.places.ErrorDomain Code=-2 "The Places API server returned a response that we couldn't understand. If you believe this error represents a bug, please file a report using the instructions on our community and support page." UserInfo={NSLocalizedFailureReason=The Places API server returned a response that we couldn't understand. If you believe this error represents a bug, please file a report using the instructions on our community and support page., NSUnderlyingError=0x600000e10ed0 {Error Domain=com.google.HTTPStatus Code=403 "Internal Error" UserInfo={NSLocalizedDescription=Internal Error}}}

查阅文档后了解到这是和服务器内部问题相关的错误,但想知道是否有人遇到过此问题及解决方法。

我已经检查过以下内容:

  • API密钥正确且配置无误
  • Google Cloud Console中已启用Places API
  • API使用配额未超限
  • 账单已激活并关联到项目

请问有人遇到过类似问题或有解决思路吗?

内容的提问来源于stack exchange,提问作者Yağız Erbay

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.17 00:45:15