Places SDK for iOS supports the existing Place Details. If you are familiar with the existing Places SDK for iOS, the new version of Place Details makes the following changes:
Uses a new pricing model. For pricing information for all APIs, see Pricing for the Places SDK for iOS (New).
Field masking is required. You must specify which fields you want returned in the response. There is no default list of returned fields. If you omit this list, the methods return an error.
To make a request, call the new
GMSPlacesClient fetchPlaceWithRequest:
method.Pass to the request:
An instance of the new
GMSFetchPlaceRequest
class that defines all request parameters, such as the place ID and session token.A callback of type
GMSPlaceResultCallback
to handle the response.
The response contains a
GMSPlace
instance containing details about the place. The values in thetypes
property of theGMSPlace
instance are now defined by Table A and Table B.The response
GMSPlace
instance contains the newreviews
property of typeGMSPlaceReview
. When your app displays information obtained from theGMSPlace
instance, such as photos and reviews, the app must also display the required attributions.For more information, see the documentation on attributions.
The response
GMSPlace
instance contains the following member functions:isOpen
calculates whether a place is open at the given time.isOpenAtDate
calculates whether a place is open on a given date.
These functions are only available when you enable Places SDK for iOS. They are not available when you enable Places SDK for iOS (New). For more information, see Choose your SDK version.
Example request
With Place Details (New), you make a request and
pass all parameters in the GMSFetchPlaceRequest
instance. This
example also uses a field mask so the response only includes the display name
and website URL for the place:
Swift
// A hotel in Saigon with an attribution. let placeID = "ChIJV4k8_9UodTERU5KXbkYpSYs" // Specify the place data types to return. let fields = [GMSPlaceProperty.name, GMSPlaceProperty.website].map {$0.rawValue} // Create the GMSFetchPlaceRequest instance. let fetchPlaceRequest = GMSFetchPlaceRequest(placeID: placeID, placeProperties: fields, sessionToken: nil) client.fetchPlaceWithRequest(fetchPlaceRequest: fetchPlaceRequest, callback: { (place: GMSPlace?, error: Error?) in guard let place, error == nil else { return } print("Place found: \(String(describing: place.name))") })
Objective-C
// A hotel in Saigon with an attribution. NSString *placeID = @"ChIJV4k8_9UodTERU5KXbkYpSYs"; // Specify the place data types to return. NSArray<NSString *> *fields = @[GMSPlacePropertyName, GMSPlacePropertyWebsite]; // Create the GMSFetchPlaceRequest instance. GMSFetchPlaceRequest *fetchPlaceRequest = [[GMSFetchPlaceRequest alloc] initWithPlaceID:placeID placeProperties: fields sessionToken:nil]; [placesClient fetchPlaceWithRequest: fetchPlaceRequest callback: ^(GMSPlace *_Nullable place, NSError *_Nullable error) { if (error != nil) { NSLog(@"An error occurred %@", [error localizedDescription]); return; } else { NSLog(@"Place Found: %@", place.name); NSLog(@"The place URL: %@", place.website); } }];