Migrate to Places Swift SDK for iOS

Migrating from Places SDK for iOS toPlaces Swift SDK for iOS should be straightforward and can be doneincrementally. Since structs in the Places Swift SDK for iOS are notcompatible with their Objective-C based counterparts, we recommend migratingdiscrete chunks of functionality based on uses of APIs in GMSPlacesClient.

Add the Places Swift SDK for iOS to your project

The following steps are required to use Places Swift SDK for iOS:

  1. Enable thePlaces API(New).
  2. Add thePlaces Swift SDKto your dependencies. You can choose to installGooglePlaces,GooglePlacesSwift, or both.

    Note: The GitHub URL to access Google Places Swift has changed. If you areupdating a version of GooglePlacesSwift that was accessed through the old URL,https://github.com/googlemaps/ios-places-swift-sdk, remove it from your Xcode'spackage dependencies section.
  3. Initialize the Places client withPlacesClient.

Step-by-step migration example

As an example, suppose an app using the Places SDK for iOSreceives autocomplete suggestions based on a text input, then fetches thedetails of the first place suggestion. UsingPlaces SDK for iOS, the existing code might look somethinglike the following:

// Initialize Places Client.GMSPlacesClient.provideAPIKey(apiKey)letclient=GMSPlacesClient.shared()// Fetch Autocomplete Request.letcenter=CLLocation(latitude:37.3913916,longitude:-122.0879074)letnorthEast=CLLocationCoordinate2DMake(37.388162,-122.088137)letsouthWest=CLLocationCoordinate2DMake(37.395804,-122.077023)letfilter=GMSAutocompleteFilter()filter.types=[kGMSPlaceTypeRestaurant]filter.origin=centerfilter.locationBias=GMSPlaceRectangularLocationOption(northEast,southWest)letrequest=GMSAutocompleteRequest(query:"Sicilian piz")request.filter=filterclient.fetchAutocompleteSuggestions(from:request){(results,error)inguardletresults,error==nilelse{print("Autocomplete error:\(String(describing:error))")return}// Fetch Place Request.guardletplaceID=results.first?.placeSuggestion?.placeIDelse{return}letmyProperties=[GMSPlaceProperty.name,GMSPlaceProperty.website].map{$0.rawValue}letfetchPlaceRequest=GMSFetchPlaceRequest(placeID:placeID,placeProperties:myProperties,sessionToken:nil)client.fetchPlace(with:fetchPlaceRequest){(place:GMSPlace?,error:Error?)inguardletplace,error==nilelse{return}print("Place found:\(String(describing:place.name));\(String(describing:place.website))")}}

Update the Places Client initializer

To modernize the code and take advantage of the new SDK's capabilities, you'llneed to replace the GMSPlacesClient with the PlacesClient. Additionally, theparameter names are changed in the new method, so you'll need to update theparameter tofrom instead ofwith. Finally, thePlaces Swift SDK uses the upgradedAutocompleteRequest.

Updated code

// Initialize Places Swift Client.let_=PlacesClient.provideAPIKey(apiKey)letplacesSwiftClient=PlacesClient.shared

Original code

// Initialize Places Client.GMSPlacesClient.provideAPIKey(apiKey)letclient=GMSPlacesClient.shared()

Update the autocomplete request

You could begin by updating the autocomplete request flow. The old code uses acallback to request autocomplete suggestions, while the new code employs aswitch/await pattern. Callbacks can add complexity to code structure anderror handling. The new Places Swift SDK supports concurrency,which simplifies asynchronous operations.

// Initialize Places Swift Client.let_=PlacesClient.provideAPIKey(apiKey)letplacesSwiftClient=PlacesClient.shared// Fetch Autocomplete Request.letcenter=CLLocation(latitude:37.3913916,longitude:-122.0879074)letnorthEast=CLLocationCoordinate2DMake(37.388162,-122.088137)letsouthWest=CLLocationCoordinate2DMake(37.395804,-122.077023)letbias=RectangularCoordinateRegion(northEast:northEast,southWest:southWest)letfilter=AutocompleteFilter(types:[.restaurant],origin:center,coordinateRegionBias:bias)letautocompleteRequest=AutocompleteRequest(query:"Sicilian piz",filter:filter)letplaceID:StringswitchawaitplacesSwiftClient.fetchAutocompleteSuggestions(with:autocompleteRequest){case.success(letresults):switchresults.first{case.place(letplaceSuggestion):placeID=placeSuggestion.placeIDcase.none:fallthrough@unknowndefault:return}case.failure(letplacesError):print("Autocomplete error:\(placesError)")return}// Initialize Places Client.GMSPlacesClient.provideAPIKey(apiKey)letplacesClient=GMSPlacesClient.shared()// Fetch Place Request.letmyProperties=[GMSPlaceProperty.name,GMSPlaceProperty.website].map{$0.rawValue}letfetchPlaceRequest=GMSFetchPlaceRequest(placeID:placeID,placeProperties:myProperties,sessionToken:nil)placesClient.fetchPlace(with:fetchPlaceRequest){(place:GMSPlace?,error:Error?)inguardletplace,error==nilelse{return}print("Place found:\(String(describing:place.name));\(String(describing:place.website))")}

Replace deprecated classes, methods, and typedefs

The following classes, methods, and typedefs in the Places SDK for iOS have been deprecated as of v10.4. They will no longer be available in the v11.0 version that will be released in Q3 2026.

This table shows the deprecated methods and their replacements:

DeprecatedReplacement
currentPlaceWithCallback orfindPlaceLikelihoodsFromCurrentLocationWithPlaceFieldssearchNearbyWithRequest
lookUpPlaceID orfetchPlaceFromPlaceIDfetchPlaceWithRequest
lookUpPhotosForPlaceID orloadPlacePhotofetchPhotoWithRequest
GMSAutocompletePredictionAutocompleteSuggestion
findAutocompletePredictionsFromQuery orGMSAutocompleteFetcherfetchAutocompleteSuggestionsFromRequest
isOpenWithPlaceID orisOpenWithPlaceisOpenWithRequest
GMSAutocompleteResultsViewController,GMSAutocompleteTableDataSource, orGMSAutocompleteViewControllerplaceAutocomplete

Update method and class names

Finally, complete the migration by refactoring thefetchPlace code andremoving both theGMSPlacesClient initialization andGMSPlacePropertydeclaration. In Places Swift SDK, the method and classnameshave been updated to remove the "GMS" prefix, and must be updated accordingly;e.g.,GMSFetchPlaceRequest becomesFetchPlaceRequest.

Type-handling

The newfetchPlace method uses improved type handling. While the old coderequired passing the property's raw values, the new code doesn't requiredevelopers to explicitly fetch raw values here, thereby improving concision andreadability.

Concurrency

Additionally, the new method supports concurrency, allowing for replacing thecallback inplacesClient.fetchPlace with aswitch/await pattern inplacesSwiftClient.fetchPlace.

// Initialize Places Swift Client.let_=PlacesClient.provideAPIKey(apiKey)letplacesSwiftClient=PlacesClient.shared// Fetch Autocomplete Request.letcenter=CLLocation(latitude:37.3913916,longitude:-122.0879074)letnorthEast=CLLocationCoordinate2DMake(37.388162,-122.088137)letsouthWest=CLLocationCoordinate2DMake(37.395804,-122.077023)letbias=RectangularCoordinateRegion(northEast:northEast,southWest:southWest)letfilter=AutocompleteFilter(types:[.restaurant],origin:center,coordinateRegionBias:bias)letautocompleteRequest=AutocompleteRequest(query:"Sicilian piz",filter:filter)letplaceID:StringswitchawaitplacesSwiftClient.fetchAutocompleteSuggestions(with:autocompleteRequest){case.success(letresults):switchresults.first{case.place(letplaceSuggestion):placeID=placeSuggestion.placeIDcase.none:fallthrough@unknowndefault:return}case.failure(letplacesError):print("Autocomplete error:\(placesError)")return}// Fetch Place Request.letfetchPlaceRequest=FetchPlaceRequest(placeID:placeID,placeProperties:[.displayName,.websiteURL])switchawaitplacesSwiftClient.fetchPlace(with:fetchPlaceRequest){case.success(letplace):print("Place found:\(place.displayName):\(String(describing:place.description))")case.failure(letplacesError):print("Place not found:\(placeID);\(placesError)")}

Stay up-to-date

Visit therelease notes page for Places Swift SDK for iOS to learnabout new features and changes.

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025-11-21 UTC.