Google Maps Platform SDKs for iOS expand Swift support, new Places APIs, and map styling
The Preview release of the Places Swift SDK for iOS brings a new generation of SDKs from Google Maps Platform that enable iOS developers to use the best features of the Swift™ programming language for more robust code. Available through both Swift Package Manager and CocoaPods, the Places Swift SDK for iOS expands on the Places SDK for iOS' support for the Swift language by adding value-types, concurrency, compile-time detection of type errors, default parameter values, and more. In addition, this summer we have released significant new features in the Maps SDK for iOS.
Ever since the introduction of the Swift language to the Apple development ecosystem in 2014, iOS developers have needed to choose between writing their code for iOS apps in Objective-C or Swift. Recent JetBrains surveys indicate that over 60% of developers’ iOS projects are written mostly in Swift.
While the Places SDK for iOS provides both Objective-C and Swift versions of its classes and methods, its underlying implementation in Objective-C limits its ability to support the most compelling features of the Swift language that offer benefits over Objective-C. In order to provide support for type-safety, Swift concurrency, and other idiomatic handling of types in Swift, the Places Swift SDK for iOS needed to be written fully in Swift.
With the introduction of the Places Swift SDK for iOS, there are now three options for bringing the Places APIs into iOS apps. Both the Places Swift SDK for iOS and the Places SDK for iOS (New) support all APIs of the Places API (New) including the new Place Autocomplete. Below is a table of distinguishing characteristics.
Example code comparison
Updating a codebase that uses the Places SDK for iOS can be done in discrete chunks to ease migration to the Places Swift SDK for iOS. Suppose an app uses Place Autocomplete to help a user enter a place of interest, then retrieves Place Details about the selected place.
The old code using Places SDK for iOS might use GMSPlacesClient.findAutocompletePredictions(fromQuery:)
with a callback to request the Autocomplete predictions based on the input query. Callbacks make code structure and error handling more complex especially if multiple asynchronous operations require nested callbacks.
placesClient?.findAutocompletePredictions(fromQuery: query,
filter: filter,
sessionToken: token,
callback: { (results, error) in
if let error = error {
// Handle error
return
}
if let results = results {
// Handle predictions
}
}
})
With the Places Swift SDK for iOS, the request and response handling can be simplified with the Swift language support for concurrency, using an asynchronous task through PlacesClient.fetchAutocompleteSuggestions(with:)
.
switch await placesClient.fetchAutocompleteSuggestions(with: autocompleteRequest) {
case .success(let autocompleteSuggestions):
// Handle suggestions.
case .failure(let placesError):
// Handle error.
}
The migration guide demonstrates conversion of a full code sample from the Places SDK for iOS to the Places Swift SDK for iOS.
Resources for trying the Places Swift SDK for iOS
The companion Places SDK for iOS sample app repository on GitHub demonstrates how to use the new Places Swift SDK for iOS. If migrating a codebase that uses the Places SDK for iOS or Places SDK for iOS (New), use the guide for migrating to the Places Swift SDK for iOS. The SDKs can be used side by side so that migration can be done gradually. The reference documentation provides full details about the Places Swift SDK for iOS.
In addition to the standard Issue Tracker for the Places SDKs for iOS, we are looking for your suggestions for API design improvements, feature requests, or bug reports through the Places Swift SDK for iOS Preview survey, which will be open through September 30, 2024. Your feedback will help shape our roadmap for iOS SDKs and libraries.
New features for the Maps SDK for iOS
Beyond the Places Swift SDK for iOS, we've also been making sure mobile developers can use all the latest capabilities of Google Maps Platform. With the release of Maps SDK for iOS v9.0.0, developers gained data-driven styling for boundaries and datasets, updated map styling to better match what users see in the Google Maps app, support for dark mode and light mode in map color schemes, and support for Apple Privacy Manifest requirements. A corresponding version of the Maps SDK for iOS Utility Library has been released to support developers who use utility functions such as marker clustering, heatmaps, and rendering KML or GeoJSON data with the Maps SDK for iOS.
Swift and the Swift logo are trademarks of Apple Inc.