Places SDK for iOS supports Place Details (Legacy). If you are familiar with Places SDK for iOS (Legacy), Place Details (New) 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
GMSFetchPlaceRequestclass that defines all request parameters, such as the place ID and session token.A callback of type
GMSPlaceResultCallbackto handle the response.
The response contains a
GMSPlaceinstance containing details about the place. The values in thetypesproperty of theGMSPlaceinstance are now defined by Table A and Table B.The response
GMSPlaceinstance contains the newreviewsproperty of typeGMSPlaceReview. When your app displays information obtained from theGMSPlaceinstance, such as photos and reviews, the app must also display the required attributions.For more information, see the documentation on attributions.
The response
GMSPlaceinstance contains the following member functions:isOpencalculates whether a place is open at the given time.isOpenAtDatecalculates 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); } }];