I'm using the Google Places SDK for iOS (version 9.2.0) to implement an autocomplete feature in my Swift app. The autocomplete search works fine, showing a list of recommended places. However, when I select a place, I encounter the following error:
Autocomplete error: Internal Error, code: 403, info: Error Domain=com.google.HTTPStatus Code=403 "Internal Error" UserInfo={NSLocalizedDescription=Internal Error}
Google Places SDK Version: 9.2.0
Steps Taken:
Here is the code I am using, which always falls into the didFailAutocompleteWithError:
import Foundation
import GooglePlaces
import SwiftUI
struct GooglePlacesSearchView: UIViewControllerRepresentable {
@Binding var selectedPlace: GMSPlace?
@Binding var locationName: String
@Binding var lat: Double
@Binding var long: Double
@Environment(\.presentationMode) var presentationMode
func makeUIViewController(context: Context) -> UIViewController {
let autocompleteController = GMSAutocompleteViewController()
autocompleteController.delegate = context.coordinator
return autocompleteController
}
func updateUIViewController(_ uiViewController: UIViewController, context: Context) {
// Update any properties or UI elements here if needed.
}
func makeCoordinator() -> Coordinator {
Coordinator(self)
}
class Coordinator: NSObject, GMSAutocompleteViewControllerDelegate {
var parent: GooglePlacesSearchView
init(_ parent: GooglePlacesSearchView) {
self.parent = parent
}
func viewController(_ viewController: GMSAutocompleteViewController, didAutocompleteWith place: GMSPlace) {
parent.selectedPlace = place
parent.presentationMode.wrappedValue.dismiss()
parent.locationName = place.name ?? ""
parent.lat = place.coordinate.latitude
parent.long = place.coordinate.longitude
}
func viewController(_ viewController: GMSAutocompleteViewController, didFailAutocompleteWithError error: Error) {
debugPrint("Autocomplete error: \(error.localizedDescription), code: \(error._code), info: \(error)")
}
func wasCancelled(_ viewController: GMSAutocompleteViewController) {
parent.presentationMode.wrappedValue.dismiss()
}
}
}
I have also tested the API using a curl request in Postman, and it works perfectly there. However, in Xcode, the issue persists. I have tried the following:
Changing the network.
Answering this as a community wiki. As stated in this github
Google Places SDK Version 9.x seems to require the new Places API (new) which you have to activate for your API key (in case it's restricted)