I ran into the same problem and then came across this message
, 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
source share