iOS应用调用Google Places Autocomplete API遇Error Code -2错误求助
我在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

