0

I am using this tutorial to create a autocomplete search box. I have created a custom adapter to populate my autocomplete text box.

mGoogleApiClient = new GoogleApiClient.Builder(ActivityMap.this)
            .addApi(Places.GEO_DATA_API)
            .enableAutoManage(this, GOOGLE_API_CLIENT_ID, this)
            .addConnectionCallbacks(this)
            .addOnConnectionFailedListener(this)
            .build();             

PendingResult<AutocompletePredictionBuffer> results =
        Places.GeoDataApi.getAutocompletePredictions(mGoogleApiClient,
                                                    constraint.toString(), 
                                                    mBounds, null);

However, I am receiving the following error message as follows:

{statusCode=ERROR_OPERATION_FAILED, resolution=null}

for the following lines of code in the getPredictions method in the Adapter

final Status status = autocompletePredictions.getStatus();
        if (!status.isSuccess()) {
            Toast.makeText(getContext(), "Error: " + status.toString(),
                    Toast.LENGTH_SHORT).show();
            Log.e(TAG, "Error getting place predictions: " + status.toString());
            autocompletePredictions.release();
            return null;
        }

PS: In the lines:

PendingResult<AutocompletePredictionBuffer> results =
                Places.GeoDataApi
                        .getAutocompletePredictions(mGoogleApiClient, constraint.toString(), 
mBounds, mPlaceFilter);

I have tried changing mPlaceFilter to null, to the same result

1 Answer 1

3

Finally, figured it out. I was writing a different API key in the Android Manifest.

Also, if you are using the Google API Key for more than one application, specify the key once only (using the Android Tutorials setup guide) and enable support for other API's within the same project.

Sign up to request clarification or add additional context in comments.

3 Comments

Can you please elaborate more I need help
If you using Google Key for more than one API(like Places, Maps, etc.), Ensure that you add only key in the android manifest and enable all the API's as needed in the application (in the Google Developers console from where you get the key details). Hope this helps. If you still have problems, let me know in which part of the answer you have problem understanding.
I solved the same problem with replacing maps API key with this:<meta-data android:name="com.google.android.geo.API_KEY" android:value="YOUR_API_KEY"/>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.