GMSPlacesClient
@interface GMSPlacesClient : NSObjectMain interface to the Places SDK. Used for searching and getting details about places. This class
should be accessed through the [GMSPlacesClient sharedClient] method.
GMSPlacesClient methods should only be called from the main thread. Calling these methods from
another thread will result in an exception or undefined behavior. Unless otherwise specified, all
callbacks will be invoked on the main thread.
-
Provides the shared instance of
GMSPlacesClientfor the Google Places SDK for iOS, creating it if necessary.If your application often uses methods of
GMSPlacesClientit may want to hold onto this object directly, as otherwise your connection to Google may be restarted on a regular basis.Declaration
Swift
class func shared() -> SelfObjective-C
+ (nonnull instancetype)sharedClient; -
Provides your API key to the Google Places SDK for iOS. This key is generated for your application via the Google Cloud Platform Console, and is paired with your application’s bundle ID to identify it. This should be called by your application before using
GMSPlacesClient(e.g., inapplication:didFinishLaunchingWithOptions:).Declaration
Swift
class func provideAPIKey(_ key: String) -> BoolObjective-C
+ (BOOL)provideAPIKey:(nonnull NSString *)key;Return Value
YES if the APIKey was successfully provided.
-
Provides an App Check token provider to the Google Places SDK for iOS. This should be called by your application before using
GMSPlacesClient(for example, inapplication:didFinishLaunchingWithOptions:). If you do not provide a token provider, the SDK will not use the token provider.Declaration
Swift
class func setAppCheckTokenProvider(_ provider: any GMSPlacesAppCheckTokenProvider)Objective-C
+ (void)setAppCheckTokenProvider: (nonnull id<GMSPlacesAppCheckTokenProvider>)provider; -
Returns the open source software license information for the Google Places SDK for iOS. This information must be made available within your application.
Declaration
Swift
class func openSourceLicenseInfo() -> StringObjective-C
+ (nonnull NSString *)openSourceLicenseInfo; -
Returns the version for this release of the Google Places SDK for iOS.. For example, “1.0.0”.
Declaration
Swift
class func sdkVersion() -> StringObjective-C
+ (nonnull NSString *)SDKVersion; -
Returns the long version for this release of the Google Places SDK for iOS.. For example, “1.0.0 (102.1)”.
Declaration
Swift
class func sdkLongVersion() -> StringObjective-C
+ (nonnull NSString *)SDKLongVersion; -
Deprecated
This method is replaced by
fetchPlaceWithRequest:callback:and will be removed in a future release.Get details for a place. This method is non-blocking.
Declaration
Swift
func lookUpPlaceID(_ placeID: String, callback: @escaping GMSPlaceResultCallback)Objective-C
- (void)lookUpPlaceID:(nonnull NSString *)placeID callback:(nonnull GMSPlaceResultCallback)callback;Parameters
placeIDThe place ID to look up.
callbackThe callback to invoke with the lookup result.
-
Find Autocomplete suggestions from text query. Results may optionally be biased towards a certain location or restricted to an area. This method is non-blocking.
The supplied callback will be invoked with an array of autocompletion suggestions upon success and an
NSErrorupon an error.Declaration
Swift
func fetchAutocompleteSuggestions(from request: GMSAutocompleteRequest, callback: @escaping GMSAutocompleteSuggestionsCallback)Objective-C
- (void) fetchAutocompleteSuggestionsFromRequest: (nonnull GMSAutocompleteRequest *)request callback: (nonnull GMSAutocompleteSuggestionsCallback) callback;Parameters
requestThe
GMSAutocompleteRequestrequest for autocomplete.callbackThe callback to invoke with the suggestions.
-
Deprecated
This method is replaced by
fetchPhotoWithRequest:callback:and will be removed in a future release.Loads the image for a specific photo at its maximum size.
Image data may be cached by the SDK. If the requested photo does not exist in the cache then a network lookup will be performed.
Declaration
Swift
func loadPlacePhoto(_ photoMetadata: GMSPlacePhotoMetadata, callback: @escaping GMSPlacePhotoImageResultCallback)Objective-C
- (void)loadPlacePhoto:(nonnull GMSPlacePhotoMetadata *)photoMetadata callback:(nonnull GMSPlacePhotoImageResultCallback)callback;Parameters
photoMetadataThe
GMSPlacePhotoMetadatafor which to load aUIImage.callbackThe callback to invoke with the loaded
UIImage. -
Deprecated
This method is replaced by
fetchPhotoWithRequest:callback:and will be removed in a future release.Loads the image for a specific photo, scaled to fit the given maximum dimensions.
The image will be scaled to fit within the given dimensions while maintaining the aspect ratio of the original image. This scaling is performed server-side.
If the scale parameter is not 1.0 maxSize will be multiplied by this value and the returned
UIImagewill be set to have the specified scale. This parameter should be set to the screen scale if you are loading images for display on screen.Image data may be cached by the SDK. If the requested photo does not exist in the cache then a network lookup will be performed.
NOTE: After applying the scale factor the dimensions in maxSize will be rounded up to the nearest integer before use. If an image is requested which is larger than the maximum size available a smaller image may be returned.
Declaration
Swift
func loadPlacePhoto(_ photoMetadata: GMSPlacePhotoMetadata, constrainedTo maxSize: CGSize, scale: CGFloat, callback: @escaping GMSPlacePhotoImageResultCallback)Objective-C
- (void)loadPlacePhoto:(nonnull GMSPlacePhotoMetadata *)photoMetadata constrainedToSize:(CGSize)maxSize scale:(CGFloat)scale callback:(nonnull GMSPlacePhotoImageResultCallback)callback;Parameters
photoMetadataThe
GMSPlacePhotoMetadatafor which to load aUIImage.maxSizeThe maximum size of the image.
scaleThe scale to load the image at.
callbackThe callback to invoke with the loaded
UIImage. -
Deprecated
This method is replaced by
searchNearbyWithRequest:callback:and will be removed in a future release.Returns an estimate of the place where the device is currently known to be located.
Generates a place likelihood list based on the device’s last estimated location. The supplied callback will be invoked with this likelihood list upon success and an NSError upon an error.
NOTE: This method requires that your app has permission to access the current device location. Before calling this make sure to request access to the users location using [CLLocationManager requestWhenInUseAuthorization] or [CLLocationManager requestAlwaysAuthorization]. If you do call this method and your app does not have the correct authorization status, the callback will be called with an error.
Declaration
Swift
func currentPlace(callback: @escaping GMSPlaceLikelihoodListCallback)Objective-C
- (void)currentPlaceWithCallback: (nonnull GMSPlaceLikelihoodListCallback)callback;Parameters
callbackThe callback to invoke with the place likelihood list.
-
Deprecated
This method is replaced by
searchNearbyWithRequest:callback:and will be removed in a future release.Find place likelihoods using the user’s current location. This method is non-blocking.
The supplied callback will be invoked with an array of places with likelihood scores upon success and an NSError upon an error.
Declaration
Swift
func findPlaceLikelihoodsFromCurrentLocation(withPlaceFields placeFields: GMSPlaceField, callback: @escaping GMSPlaceLikelihoodsCallback)Objective-C
- (void) findPlaceLikelihoodsFromCurrentLocationWithPlaceFields: (GMSPlaceField)placeFields callback: (nonnull GMSPlaceLikelihoodsCallback) callback;Parameters
placeFieldsThe individual place fields requested for the place objects in the list.
callbackThe callback to invoke with place likelihoods.
-
Deprecated
This method is replaced by
fetchAutocompleteSuggestionsFromRequest:callback:and will be removed in a future release.Find Autocomplete predictions from text query. Results may optionally be biased towards a certain location or restricted to an area. This method is non-blocking.
The supplied callback will be invoked with an array of autocompletion predictions upon success and an NSError upon an error.
Declaration
Swift
func findAutocompletePredictions(fromQuery query: String, filter: GMSAutocompleteFilter?, sessionToken: GMSAutocompleteSessionToken?, callback: @escaping GMSAutocompletePredictionsCallback)Objective-C
- (void) findAutocompletePredictionsFromQuery:(nonnull NSString *)query filter: (nullable GMSAutocompleteFilter *)filter sessionToken: (nullable GMSAutocompleteSessionToken *) sessionToken callback: (nonnull GMSAutocompletePredictionsCallback) callback;Parameters
queryThe partial text to autocomplete.
filterThe filter to apply to the results. This parameter may be nil.
sessionTokenThe
GMSAutocompleteSessionTokento associate request to a billing session.callbackThe callback to invoke with the predictions.
-
Deprecated
This method is replaced by
fetchPlaceWithRequest:callback:and will be removed in a future release.Gets the metadata for up to 10 photos associated with a place.
Photos are sourced from a variety of locations, including business owners and photos contributed by Google+ users. In most cases, these photos can be used without attribution, or will have the required attribution included as a part of the image. However, you must use the
attributionsproperty in the response to retrieve any additional attributions required, and display those attributions in your application wherever you display the image. A maximum of 10 photos are returned.Multiple calls of this method will probably return the same photos each time. However, this is not guaranteed because the underlying data may have changed.
This method performs a network lookup.
Declaration
Swift
func lookUpPhotos(forPlaceID placeID: String, callback: @escaping GMSPlacePhotoMetadataResultCallback)Objective-C
- (void)lookUpPhotosForPlaceID:(nonnull NSString *)placeID callback: (nonnull GMSPlacePhotoMetadataResultCallback)callback;Parameters
placeIDThe place ID for which to look up photos.
callbackThe callback to invoke with the lookup result.
-
Deprecated
This method is replaced by
isOpenWithRequest:callback:and will be removed in a future release.Gets details for a place including all fields necessary to determine
GMSPlaceOpenStatusat the current time. This method is non-blocking.Declaration
Swift
func isOpen(withPlaceID placeID: String, callback: @escaping GMSPlaceOpenStatusCallback)Objective-C
- (void)isOpenWithPlaceID:(nonnull NSString *)placeID callback:(nonnull GMSPlaceOpenStatusCallback)callback;Parameters
placeIDThe place ID to look up.
callbackThe callback to invoke with the place result.
-
Deprecated
This method is replaced by
isOpenWithRequest:callback:and will be removed in a future release.Gets details for a place including all fields necessary to determine
GMSPlaceOpenStatusat the specifiedNSDate. This method is non-blocking.Declaration
Swift
func isOpen(withPlaceID placeID: String, date: Date, callback: @escaping GMSPlaceOpenStatusCallback)Objective-C
- (void)isOpenWithPlaceID:(nonnull NSString *)placeID date:(nonnull NSDate *)date callback:(nonnull GMSPlaceOpenStatusCallback)callback;Parameters
placeIDThe place ID to look up.
dateThe
NSDateto determine open status for.callbackThe callback to invoke with the place result.
-
Deprecated
This method is replaced by
isOpenWithRequest:callback:and will be removed in a future release.Gets details for a place including all fields necessary to determine
GMSPlaceOpenStatusat the current time. Only requests additional fields if theGMSPlacedoes not have all necessary fields, otherwiseGMSPlaceOpenStatuswill be returned in the callback immediately. This method is non-blocking.Declaration
Swift
func isOpen(with place: GMSPlace, callback: @escaping GMSPlaceOpenStatusCallback)Objective-C
- (void)isOpenWithPlace:(nonnull GMSPlace *)place callback:(nonnull GMSPlaceOpenStatusCallback)callback;Parameters
placeThe
GMSPlaceto look up.callbackThe callback to invoke with the place result.
-
Deprecated
This method is replaced by
isOpenWithRequest:callback:and will be removed in a future release.Gets details for a place including all fields necessary to determine
GMSPlaceOpenStatusat the specifiedNSDate. Only requests additional fields if theGMSPlacedoes not have all necessary fields, otherwiseGMSPlaceOpenStatuswill be returned in the callback immediately. This method is non-blocking.Declaration
Swift
func isOpen(with place: GMSPlace, date: Date, callback: @escaping GMSPlaceOpenStatusCallback)Objective-C
- (void)isOpenWithPlace:(nonnull GMSPlace *)place date:(nonnull NSDate *)date callback:(nonnull GMSPlaceOpenStatusCallback)callback;Parameters
placeThe
GMSPlaceto look up.dateThe
NSDateto determine open status for.callbackThe callback to invoke with the place result.
-
Deprecated
This method is replaced by
fetchPlaceWithRequest:callback:callback:and will be removed in a future release.Fetch details for a place. This method is non-blocking.
Declaration
Swift
func fetchPlace(fromPlaceID placeID: String, placeFields: GMSPlaceField, sessionToken: GMSAutocompleteSessionToken?, callback: @escaping GMSPlaceResultCallback)Objective-C
- (void)fetchPlaceFromPlaceID:(nonnull NSString *)placeID placeFields:(GMSPlaceField)placeFields sessionToken: (nullable GMSAutocompleteSessionToken *)sessionToken callback:(nonnull GMSPlaceResultCallback)callback;Parameters
placeIDThe place ID to look up.
placeFieldsThe individual place fields requested for the place objects in the list.
sessionTokenThe
GMSAutocompleteSessionTokento associate request to a billing session.callbackThe callback to invoke with the lookup result.
-
Gets the open status for a place. Gets details for a place including all properties necessary to determine
GMSPlaceOpenStatusat the specifiedNSDate. This method is non-blocking.Declaration
Swift
func isOpen(with isOpenRequest: GMSPlaceIsOpenRequest, callback: @escaping GMSPlaceOpenStatusResponseCallback)Objective-C
- (void)isOpenWithRequest:(nonnull GMSPlaceIsOpenRequest *)isOpenRequest callback:(nonnull GMSPlaceOpenStatusResponseCallback)callback;Parameters
isOpenRequestThe request to determine the open status for a given place.
callbackThe callback to invoke with the open status response.
-
Search for places by text and restrictions. This method is non-blocking.
Declaration
Swift
func searchByText(with textSearchRequest: GMSPlaceSearchByTextRequest, callback: @escaping GMSPlaceSearchByTextResultCallback)Objective-C
- (void)searchByTextWithRequest: (nonnull GMSPlaceSearchByTextRequest *)textSearchRequest callback: (nonnull GMSPlaceSearchByTextResultCallback)callback;Parameters
textSearchRequestGMSPlaceSearchByTextRequestThe text request to use for the query.callbackThe callback to invoke with the lookup result.
-
Get a place using a request object. This method is non-blocking.
Declaration
Swift
func fetchPlace(with fetchPlaceRequest: GMSFetchPlaceRequest, callback: @escaping GMSPlaceResultCallback)Objective-C
- (void)fetchPlaceWithRequest:(nonnull GMSFetchPlaceRequest *)fetchPlaceRequest callback:(nonnull GMSPlaceResultCallback)callback;Parameters
fetchPlaceRequestGMSFetchPlaceRequestThe fetch place request to use for the query.callbackThe callback to invoke with the place result.
-
Request a photo using fetch photo request. This method is non-blocking.
Declaration
Swift
func fetchPhoto(with fetchPhotoRequest: GMSFetchPhotoRequest, callback: @escaping GMSFetchPhotoResultCallback)Objective-C
- (void)fetchPhotoWithRequest:(nonnull GMSFetchPhotoRequest *)fetchPhotoRequest callback:(nonnull GMSFetchPhotoResultCallback)callback;Parameters
fetchPhotoRequestGMSFetchPhotoRequestThe photo request to use.callbackThe callback to invoke with the
NSURLresult. -
Search for places near a location and restriction. This method is non-blocking.
Declaration
Swift
func searchNearby(with searchNearbyRequest: GMSPlaceSearchNearbyRequest, callback: @escaping GMSPlaceSearchNearbyResultCallback)Objective-C
- (void)searchNearbyWithRequest: (nonnull GMSPlaceSearchNearbyRequest *)searchNearbyRequest callback: (nonnull GMSPlaceSearchNearbyResultCallback)callback;Parameters
searchNearbyRequestGMSPlaceSearchNearbyRequestThe search nearby request to use for the query.callbackThe callback to invoke with the lookup result.
-
Adds a usage attribution ID to the initializer, which helps Google understand which libraries and samples are helpful to developers, such as usage of a marker clustering library. To opt out of sending the usage attribution ID, it is safe to delete this function call or replace the value with an empty string.
Declaration
Swift
class func addInternalUsageAttributionID(_ internalUsageAttributionID: String)Objective-C
+ (void)addInternalUsageAttributionID: (nonnull NSString *)internalUsageAttributionID;Parameters
internalUsageAttributionIdThe usage attribution ID to add