Google Places API Android: Autocompletion closes too quickly

百般思念 提交于 2019-12-06 02:40:44

问题


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.


回答1:


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




回答2:


Change the API Key solved my problem.

You can generate new key from here




回答3:


It does sound like a key problem. Things to double-check:

  • The key is an Android key, not a web key.
  • The package name restrict on the key actually matches the package name of your app, and it is signed correctly.
  • You haven't exceeded the 1000 requests/day limit.


来源:https://stackoverflow.com/questions/40657648/google-places-api-android-autocompletion-closes-too-quickly

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!