This guide summarizes the changes and steps required to migrate your project from Places Android KTX v3.x to v4.0.0.
Warning
This library is approaching end-of-life. We plan to icebox the library and archive this repository in the very near term. Users are strongly encouraged to migrate to the official SDK implementations immediately.
Version 4.0.0 is a major release that transitions this library into a compatibility shim. Most functionality has been moved to the official Places SDK for Android.
The custom KTX extensions previously provided by this library (await* functions) are now deprecated in favor of the official SDK implementations.
Old (v3.x):
import com.google.android.libraries.places.ktx.api.net.awaitFetchPlaceNew (v4.0.0+):
import com.google.android.libraries.places.api.net.kotlin.awaitFetchPlaceNote
The extension functions in this library now delegate to the official SDK versions. You should update your imports to use the SDK versions directly.
The following legacy components have been removed.
The entire AutocompleteSupportFragment.kt file has been deleted.
- Removed:
AutocompleteSupportFragment.placeSelectionEvents() - Removed:
PlaceSelectionResult,PlaceSelectionSuccess, andPlaceSelectionErrorclasses. - Migration: The
AutocompleteSupportFragmentitself is deprecated in the official SDK. UsePlaceAutocompleteActivityinstead or migrate to the Compose-based patterns shown in the demo app.
- Removed:
fetchPhotoRequest(...)(associated with the removedFetchPhotoAPI). - Removed:
findCurrentPlaceRequest(...)(associated with the removedFindCurrentPlaceAPI).
- Removed:
PlacesClient.awaitSearchNearbyPlace(...). - Migration: Use
PlacesClient.awaitSearchNearby(...)instead.
Some APIs were moved to new files to better match modern SDK naming conventions.
| Old File | New File | API Maintained |
|---|---|---|
FetchPhotoRequest.kt |
FetchResolvedPhotoUriRequest.kt |
fetchResolvedPhotoUriRequest |
FindCurrentPlaceRequest.kt |
SearchNearbyRequest.kt |
searchNearbyRequest |
The FindCurrentPlace API has been removed in favor of SearchNearby.
Old (v3.x):
val response = placesClient.findCurrentPlace(
findCurrentPlaceRequest(listOf(Place.Field.ID, Place.Field.NAME))
).await()New (v4.0.0+):
val locationRestriction = CircularBounds.newInstance(latLng, 1000.0)
val response = placesClient.awaitSearchNearby(
locationRestriction,
listOf(Place.Field.ID, Place.Field.NAME)
)
// Or use the maintained request builder:
val request = searchNearbyRequest(locationRestriction, listOf(Place.Field.ID))Tip
See PlacesPhotoViewModel.kt#L188-L230 for a complete implementation of SearchNearby.
The FetchPhoto API (returning a Bitmap) is replaced by FetchResolvedPhotoUri (returning a Uri).
Old (v3.x):
val response = placesClient.fetchPhoto(fetchPhotoRequest(metadata)).await()
val bitmap = response.bitmapNew (v4.0.0+):
val response = placesClient.awaitFetchResolvedPhotoUri(metadata)
val uri = response.uri
// Use a library like Coil or Glide to load the URI into an ImageView/ComposeTip
See PlacesPhotoViewModel.kt#L144-L179 for a complete implementation of FetchResolvedPhotoUri.
The PriceLevel enum and its builder extensions are deprecated. You should migrate to using raw integers directly in setPriceLevels.
Old (v3.x):
val request = searchByTextRequest(query, fields) {
setPriceLevels(listOf(PriceLevel.MODERATE, PriceLevel.EXPENSIVE))
}New (v4.0.0+):
// Option 1: Use raw integers directly (1=INEXPENSIVE, 2=MODERATE, etc.)
val request = SearchByTextRequest.builder(query, fields)
.setPriceLevels(listOf(2, 3))
.build()
// Option 2: Define a local enum in your project for type safety
enum class MyPriceLevel(val value: Int) {
FREE(0), INEXPENSIVE(1), MODERATE(2), EXPENSIVE(3), VERY_EXPENSIVE(4)
}
val request = SearchByTextRequest.builder(query, fields)
.setPriceLevels(listOf(MyPriceLevel.MODERATE.value, MyPriceLevel.EXPENSIVE.value))
.build()- FetchResolvedPhotoUri: Unlike
FetchPhoto, this API returns aUriinstead of aBitmap. This is more efficient for modern Android apps using image loading libraries (Coil, Glide, etc.). - Cancellation Safety: All
await*functions in this library now delegate directly to the official SDK's nativesuspendfunctions. These are built to handle coroutine cancellation correctly, ensuring that associated SDK tasks are cancelled and resources are released if the calling coroutine is cancelled.
The following APIs are now deprecated shims that delegate to the official SDK:
| File | API |
|---|---|
PlacesClient.kt |
awaitFetchPlace, awaitFetchResolvedPhotoUri, awaitFindAutocompletePredictions, awaitSearchNearby, awaitIsOpen, awaitSearchByText |
| DSL Builders (Net) | fetchPlaceRequest, fetchResolvedPhotoUriRequest, findAutocompletePredictionsRequest, isOpenRequest, searchNearbyRequest, searchByTextRequest |
| DSL Builders (Models) | place, photoMetadata, addressComponent, autocompletePrediction, openingHours, period, plusCode |
Tip
Most model builders (like place { ... }) are now natively provided by the official SDK in the com.google.android.libraries.places.api.model.kotlin package.
Update your build.gradle to reference the new version:
dependencies {
implementation("com.google.maps.android:places-ktx:4.0.0") // {x-release-please-version}
}The demo application has been completely modernized:
- UI: Migrated to Jetpack Compose and Material 3.
- Architecture: Implemented Hilt and ViewModel.
- SDK: Upgraded to Places SDK v5.1.1.
Refer to the app directory for reference implementations using modern Android practices.