Closing Android Place autocomplete fragment yourself

I am trying to implement a place autocomplete fragment for the first time and run into one problem with it. When I start typing, after the first letter it starts searching and instead of showing the results, it (fragment) just disappears .. that I get Status {statusCode = PLACES_API_ACCESS_NOT_CONFIGURED, permission = null}

manifest.xml

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

Xml_layout

 <TextView android:text="TextView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentTop="true" android:layout_marginTop="14dp" android:id="@+id/Area" android:onClick="Onselection" android:layout_alignParentEnd="true" android:layout_alignParentStart="true" /> <fragment android:id="@+id/place_autocomplete_fragment" android:layout_width="match_parent" android:layout_height="wrap_content" android:name="com.google.android.gms.location.places.ui.PlaceAutocompleteFragment" android:layout_below="@+id/Area" android:layout_alignParentStart="true" /> 

the class

 public class test extends AppCompatActivity implements PlaceSelectionListener { private static final String LOG_TAG = "PlaceSelectionListener"; private static final LatLngBounds BOUNDS_MOUNTAIN_VIEW = new LatLngBounds( new LatLng(-85, -180), new LatLng(85, 180)); private static final int REQUEST_SELECT_PLACE = 1000; TextView locationtext ; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_testtttt); locationtext = (TextView) findViewById(R.id.Arear) ; PlaceAutocompleteFragment autocompleteFragment = (PlaceAutocompleteFragment) getFragmentManager().findFragmentById(R.id.place_autocomplete_fragment); autocompleteFragment.setOnPlaceSelectedListener(this); AutocompleteFilter typeFilter = new AutocompleteFilter.Builder() .setTypeFilter(AutocompleteFilter.TYPE_FILTER_ADDRESS) .build(); autocompleteFragment.setFilter(typeFilter); } public void Onselection(View v) { try { Intent intent = new PlaceAutocomplete.IntentBuilder (PlaceAutocomplete.MODE_OVERLAY) .setBoundsBias(BOUNDS_MOUNTAIN_VIEW) .build(testtttt.this); startActivityForResult(intent, REQUEST_SELECT_PLACE); } catch (GooglePlayServicesRepairableException | GooglePlayServicesNotAvailableException e) { e.printStackTrace(); } } @Override public void onPlaceSelected(Place place) { } @Override public void onError(Status status) { } 

Click fragment will appear

the fragment disappears / closes by itself

+6
source share
4 answers

This is a very intriguing experience when developing using the Google APIs on Android. All you have to do is:

What is it.

+23
source

rand_mem_RAM is right.
Took me 2 days googling, maybe got around the answer because it is just simple.

  • Go to console.developers.google.com
  • Select the project associated with the Google API key.
  • Enable google places API for Android 3a. Click the FIRST BLUE BUTTON button at the top of the web page, the following web page 3b will open. Then click SECOND BLUE BUTTON at the top of the next web page. Then check your device.

It would be helpful but could not be a guest.

+4
source

I ran into the same problem and then came across this message enter image description here , here is the link if you want to check yourself. Places SDK for Android .
In short, I switched to the new APIS, whose instructions are given here. Switching to the new Places SDK client

In my case, my map is on a fragment, and the search was on top of the map

build.gradle

  implementation "com.google.android.gms:play-services-location:16.0.0" implementation "com.google.android.gms:play-services-maps:16.1.0" implementation 'com.google.android.libraries.places:places:1.0.0' 

Please note that the place APIs are new and new 1.0.0. These APIs gave me:
com.google.android.gms.maps.SupportMapFragment for MAP
com.google.android.libraries.places.widget.AutocompleteSupportFragment for the search bar

  <fragment android:id="@+id/map" android:name="com.google.android.gms.maps.SupportMapFragment" android:layout_width="0dp" android:layout_height="0dp" android:layout_marginBottom="16dp" android:layout_marginTop="16dp" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" /> <fragment android:id="@+id/f_auto_complete" android:name="com.google.android.libraries.places.widget.AutocompleteSupportFragment" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_marginStart="16dp" android:layout_marginTop="16dp" android:layout_marginEnd="16dp" android:minHeight="@dimen/size_search_view" app:layout_constraintEnd_toEndOf="@+id/map" app:layout_constraintStart_toStartOf="@id/map" app:layout_constraintTop_toTopOf="@id/map" /> 

Fragment

 private fun initAutoCompleteView() { activity?.let { a -> if (!Places.isInitialized()) { Places.initialize(a.applicationContext, "YOUR API KEY") } fragment = childFragmentManager.findFragmentById(R.id.f_auto_complete) as AutocompleteSupportFragment fragment?.let { it.setPlaceFields(Arrays.asList(Place.Field.ID, Place.Field.NAME, Place.Field.LAT_LNG)) it.setOnPlaceSelectedListener(object : PlaceSelectionListener { override fun onPlaceSelected(place: Place) { Log.i("Places", place.name) } } override fun onError(status: Status) { Log.i("Places", "An error occurred: $status") } }) } } } 

To simplify life, I also add imports in case one of the classes does not fit together.

 import com.google.android.libraries.places.api.Places import com.google.android.libraries.places.api.model.Place import com.google.android.libraries.places.widget.AutocompleteSupportFragment import com.google.android.libraries.places.widget.listener.PlaceSelectionListener 
+2
source

Sometimes a problem may occur due to the SHA1 fingerprint, in my case, after replacing the debug sha1 key with the debug sha1 application extension

0
source

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


All Articles