I am trying to use places api in android app. But I got error status code 9011. As per the documentation (https://developers.google.com/places/android-sdk/reference/com/google/android/libraries/places/api/net/PlacesStatusCodes) this error code means Operation failed due to authorization issues. Billing is enabled on account and maps and places API is enabled. Maps API is working on the app.
Here is the code:
if (!Places.isInitialized())
Places.initialize(getApplicationContext(),getResources().getString(R.string.map_api_key));
AutocompleteSessionToken token = AutocompleteSessionToken.newInstance();
// Create a RectangularBounds object.
// Use the builder to create a FindAutocompletePredictionsRequest.
FindAutocompletePredictionsRequest request = FindAutocompletePredictionsRequest.builder()
// Call either setLocationBias() OR setLocationRestriction().
//.setLocationRestriction(bounds)
.setCountry("ng")//Nigeria
.setTypeFilter(TypeFilter.ADDRESS)
.setSessionToken(token)
.setQuery("SaltLak")
.build();
placesClient.findAutocompletePredictions(request).addOnSuccessListener(response -> {
StringBuilder mResult = new StringBuilder();
for (AutocompletePrediction prediction : response.getAutocompletePredictions()) {
mResult.append(" ").append(prediction.getFullText(null) + "\n");
Log.i(TAG, prediction.getPlaceId());
Log.i(TAG, prediction.getPrimaryText(null).toString());
}
Log.i(TAG, mResult.toString());
}).addOnFailureListener((exception) -> {
if (exception instanceof ApiException) {
ApiException apiException = (ApiException) exception;
Log.e(TAG, "Place not found: " + apiException.getStatusCode());
}
});