10

I have created a project under google developer console and wanted to use Google Places API for Android. I have enabled the API and integrated into my android application as per the guidelines on Google developer website (https://developers.google.com/places/android/start). The API is giving this error and after hours (and days) of debugging and searching the internet I couldn't narrow down the problem. Any leads would be appreciated about why this error is coming up.

Error: Status{statusCode=NETWORK_ERROR, resolution=null}

The following is the function from the google sample code where Places Auto Complete is invoked.

private ArrayList<PlaceAutocomplete> getAutocomplete(CharSequence constraint) {
    if (mGoogleApiClient != null) {
        Log.i(TAG, "Starting autocomplete query for: " + constraint);

        // Submit the query to the autocomplete API and retrieve a PendingResult that will
        // contain the results when the query completes.
        PendingResult<AutocompletePredictionBuffer> results =
                Places.GeoDataApi
                        .getAutocompletePredictions(mGoogleApiClient, constraint.toString(),
                                mBounds, mPlaceFilter);

        // This method should have been called off the main UI thread. Block and wait for at most 60s
        // for a result from the API.
        AutocompletePredictionBuffer autocompletePredictions = results
                .await(60, TimeUnit.SECONDS);

        // Confirm that the query completed successfully, otherwise return null
        final Status status = autocompletePredictions.getStatus();
        if (!status.isSuccess()) {
            Toast.makeText(getContext(), "Error contacting API: " + status.toString(),
                    Toast.LENGTH_SHORT).show();
            Log.e(TAG, "Error getting autocomplete prediction API call: " + status.toString());
            autocompletePredictions.release();
            return null;
        }

        Log.i(TAG, "Query completed. Received " + autocompletePredictions.getCount()
                + " predictions.");

        // Copy the results into our own data structure, because we can't hold onto the buffer.
        // AutocompletePrediction objects encapsulate the API response (place ID and description).

        Iterator<AutocompletePrediction> iterator = autocompletePredictions.iterator();
        ArrayList resultList = new ArrayList<>(autocompletePredictions.getCount());
        while (iterator.hasNext()) {
            AutocompletePrediction prediction = iterator.next();
            // Get the details of this prediction and copy it into a new PlaceAutocomplete object.
            resultList.add(new PlaceAutocomplete(prediction.getPlaceId(),
                    prediction.getDescription()));
        }

        // Release the buffer now that all data has been copied.
        autocompletePredictions.release();

        return resultList;
    }
    Log.e(TAG, "Google API client is not connected for autocomplete query.");
    return null;
}

AndroidManifiest.xml permissions

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
<uses-feature android:glEsVersion="0x00020000" android:required="true"/>
9

9 Answers 9

7

Himanshu is right; it happens to me as well I wanted to filter by cities and added:

AutocompleteFilter.create(Arrays.asList(
    Place.TYPE_LOCALITY, Place.TYPE_ADMINISTRATIVE_AREA_LEVEL_3));

this result in Status{statusCode=NETWORK_ERROR, resolution=null}

Not all constant from Place are available for filtering with AutocompleteFilter, only two are available on Android: Place.TYPE_GEOCODE and Place.TYPE_ESTABLISHMENT ('address' appear in documentation but not as constant in Place)

Read carefully here:https://developers.google.com/places/supported_types#table3

If any other constant (e.g. Place.TYPE_LOCALITY) are used the request will result in a confusing status error.

5
Please ensure the folowing.

1. The package name given in console registration page is same as that of actvity/fragment we are using. ie; if are using this auto search button inside com.example.rajeesh.UI.fragements.SearchFragment, 
then inside console registration page  package name should be 
com.example.rajeesh.UI.fragements
This is different from the package name we given in manifest file.

2. Inside manifest please  change 
  <meta-data
                android:name="com.google.android.maps.v2.API_KEY"
                android:value="@string/google_maps_api_key" />
to

      <meta-data
                android:name="com.google.android.geo.API_KEY"
                android:value="@string/google_maps_api_key" />


3. Enable Google Places API for Android in console page.
4

You can put null instead of AutocompleteFilter property in getAutocompletePredictions method if you want to get predictions of any types.

4
  • 1
    Can you share the reason if you know why a filter did not work in first place? Apr 29, 2015 at 8:05
  • 1
    Actually I don't know reason. Furthermore I need to use filters but don't know hot to. Apr 29, 2015 at 8:10
  • 1
    didn't work for me. Do u have any other suggestions?
    – sk1pro99
    Jul 10, 2015 at 10:37
  • I am having a similar kind of problem, but not exactly the same - stackoverflow.com/questions/31640783/… Anyone, please help?
    – zookastos
    Jul 26, 2015 at 22:46
2

For me, I had given meta tag for both Map and Geo.

<meta-data
        android:name="com.google.android.geo.API_KEY"
        android:value="*********************"/>
<meta-data
        android:name="com.google.android.maps.v2.API_KEY"
        android:value="**********************" />

then I removed Map meta and then it started working.

0

Problem with your code could be that you are using place type other than establishment, address and geo code in your AutoCompleteFilter. As of now only these three are supported. Code parts from Google's docs.

Optional: An AutocompleteFilter containing a set of place types, which you can use to restrict the results to one or more types of place. The following place types are supported in the filter: geocode – Returns only geocoding results, rather than businesses. Generally, you use this request to disambiguate results where the location specified may be indeterminate. address – Returns only autocomplete results with a precise address. Generally, you use this request when you know the user will be looking for a fully specified address. establishment – Returns only places that are businesses.

0

Places API has been changed since January 2019: Try changing the implementation: implementation 'com.google.android.gms:play-services-places:16.0.0' to 'implementation 'com.google.android.libraries.places:places-compat:2.1.0'

0

For Google Place API You guys need to enable billing system from Google Cloud . Because now Google no more providing free places API.

0

According to this, Place Picker is no longer available

-1

I think you should post your manifest permissions.

Also check this. Similar error message caused by wrong package name in google console

0

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.