Google Places API for Android Error: status {statusCode = NETWORK_ERROR, permission = null}

I created a project under the Google Developer Console and wanted to use the Google Places API for Android. I turned on the API and integrated it into the Android app as recommended on the Google developer website ( https://developers.google.com/places/android/start ). The API gives this error, and after several hours (and days) of debugging and searching on the Internet, I could not narrow down the problem. Any conclusions will be appreciated as to why this error occurs.

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

The following is a function from the Google example code that calls "Launch fleets".

 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"/> 
+6
source share
6 answers

You can put null instead of the AutocompleteFilter property in the getAutocompletePredictions method if you want to receive forecasts of any type.

+2
source

Himanshu is right; this happens to me, and also I wanted to filter by city 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 Place constants are available for filtering using AutocompleteFilter, on Android only two are available: Place.TYPE_GEOCODE and Place.TYPE_ESTABLISHMENT ('address' is displayed in the documentation, but not as a constant in Place )

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

If any other constant is used (for example, Place.TYPE_LOCALITY ), the request will result in a confusing status error.

+6
source

The problem with your code may be that you are using a different type of location than the installation location, address, and geocode in your autocomplete. Only these three are currently supported. Code details from Google docs.

Optional: AutocompleteFilter containing a set of place types that you can use to limit the results to one or more place types. the following types of locations are supported in the filter: geocode - Returns only the results of geocoding, not the enterprise. Typically, you use this query to disambiguate results where the specified location may be undefined. address - returns only autocomplete results using the exact address. Typically, you use this query when you know the user will search for the fully specified address. creation - Returns only those sites that are enterprises.

0
source

For me, I gave a meta tag for 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 deleted Map meta and then started working.

0
source
 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. 
0
source

I think you should publish your permissions for the manifest.

Also check this one out . A similar error message caused by an invalid package name in the Google console

-1
source

Source: https://habr.com/ru/post/985872/


All Articles