I added Place Autocompletion to my android app. When I click a button (chooseLocationButton
) it opens the Autocomplete widget correctly. The problem is when I want to write a name in the search field. Directly after clicked on the first keystroke, the Autocomplete widget close and the research is not done.
Here it is what it is written in the Run console:
W/IInputConnectionWrapper: reportFullscreenMode on inexistent InputConnection
W/IInputConnectionWrapper: finishComposingText on inactive InputConnection
Here it is the code:
AutocompleteFilter.Builder a = new AutocompleteFilter.Builder();
try {
final Intent intent = new PlaceAutocomplete.IntentBuilder(PlaceAutocomplete.MODE_FULLSCREEN)
.setFilter(a.setTypeFilter(AutocompleteFilter.TYPE_FILTER_REGIONS).build())
.build(this);
chooseLocationButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivityForResult(intent, PLACE_AUTOCOMPLETE_REQUEST_CODE);
}
});
} catch (GooglePlayServicesRepairableException e) {
e.printStackTrace();
// TODO handle exception!
} catch (GooglePlayServicesNotAvailableException e) {
e.printStackTrace();
// TODO handle exception! Toast?
}
Of course I have enabled Google Places android API and Google Map android API in the Google Developer Console. Also I have added the API key to the AndroidManifest.xml like that:
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="@string/google_maps_key" />
In the log I observe this:
BasicNetwork.performRequest: Unexpected response code 400 for https://www.googleapis.com/placesandroid/v1/getAutocompletePredictions...
Followed by:
[67738] BasicNetwork.performRequest: Unexpected response code 403 for https://www.googleapis.com/placesandroid/v1/getAutocompletePredictions?key=...11-17 21:02:01.207 1053-1543/? E/Places: PLACES_API_INVALID_APP
In the Run Log of Android Studio I have: PLACES_API_KEY_EXPIRED
I hope somebody can help me.
Thank you.
The autocomplete widget is a search dialog with built-in autocomplete functionality. As a user enters search terms, the widget presents a list of predicted places to choose from. When the user makes a selection, a Place instance is returned, which your app can then use to get details about the selected place.
The Places SDK for Android uses a pay-as-you-go pricing model. Places SDK for Android requests for the Places SDK for Android are billed by SKU. Along with the overall Google Terms of Use, there are usage limits specific to the Places SDK for Android.
Go to the Google Developers Console. Create or select a project. Click Continue to Enable the API. Go to Credentials to get a Server key (and set the API credentials).
The problem was solved when I noticed that Google had created an .xml file for the API key and that created a conflict with the API that I put in the string.xml
Change the API Key solved my problem.
You can generate new key from here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With