Google Places API for Android Error: Status{statusCode=NETWORK_ERROR, resolution=null}

梦想与她 提交于 2019-11-29 13:28:24

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

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.

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.

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.

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.

X3Btel

I think you should post your manifest permissions.

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

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