GMSPlacesClient.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. //
  2. // GMSPlacesClient.h
  3. // Google Places SDK for iOS
  4. //
  5. // Copyright 2016 Google LLC
  6. //
  7. // Usage of this SDK is subject to the Google Maps/Google Earth APIs Terms of
  8. // Service: https://developers.google.com/maps/terms
  9. //
  10. #import <CoreLocation/CoreLocation.h>
  11. #import <UIKit/UIKit.h>
  12. #import "GMSPlace.h"
  13. #import "GMSPlaceFieldMask.h"
  14. #import "GMSPlacesDeprecationUtils.h"
  15. #import "GMSPlacesErrors.h"
  16. @class GMSAutocompleteFilter;
  17. @class GMSAutocompletePrediction;
  18. @class GMSAutocompleteSessionToken;
  19. @class GMSPlaceLikelihood;
  20. @class GMSPlaceLikelihoodList;
  21. @class GMSPlacePhotoMetadata;
  22. @class GMSPlacePhotoMetadataList;
  23. NS_ASSUME_NONNULL_BEGIN
  24. /**
  25. * Callback type for receiving place details lookups. If an error occurred,
  26. * |result| will be nil and |error| will contain information about the error.
  27. * @param result The |GMSPlace| that was returned.
  28. * @param error The error that occurred, if any.
  29. *
  30. * @related GMSPlacesClient
  31. */
  32. typedef void (^GMSPlaceResultCallback)(GMSPlace *_Nullable result, NSError *_Nullable error);
  33. /**
  34. * Callback type for receiving place likelihood lists. If an error occurred, |likelihoodList| will
  35. * be nil and |error| will contain information about the error.
  36. * @param likelihoodList The list of place likelihoods.
  37. * @param error The error that occurred, if any.
  38. *
  39. * @related GMSPlacesClient
  40. */
  41. typedef void (^GMSPlaceLikelihoodListCallback)(GMSPlaceLikelihoodList *_Nullable likelihoodList,
  42. NSError *_Nullable error);
  43. /**
  44. * Callback type for receiving array of |GMSPlaceLikelihood|s. If an error occurred, the array will
  45. * be nil and |error| will contain information about the error.
  46. *
  47. * @related GMSPlacesClient
  48. */
  49. typedef void (^GMSPlaceLikelihoodsCallback)(NSArray<GMSPlaceLikelihood *> *_Nullable likelihoods,
  50. NSError *_Nullable error);
  51. /**
  52. * Callback type for receiving autocompletion results. |results| is an array of
  53. * GMSAutocompletePredictions representing candidate completions of the query.
  54. * @param results An array of |GMSAutocompletePrediction|s.
  55. * @param error The error that occurred, if any.
  56. *
  57. * @related GMSPlacesClient
  58. */
  59. typedef void (^GMSAutocompletePredictionsCallback)(
  60. NSArray<GMSAutocompletePrediction *> *_Nullable results, NSError *_Nullable error);
  61. /**
  62. * Callback type for receiving place photos results. If an error occurred, |photos| will be nil and
  63. * |error| will contain information about the error.
  64. * @param photos The result containing |GMSPlacePhotoMetadata| objects.
  65. * @param error The error that occurred, if any.
  66. *
  67. * @related GMSPlacesClient
  68. */
  69. typedef void (^GMSPlacePhotoMetadataResultCallback)(GMSPlacePhotoMetadataList *_Nullable photos,
  70. NSError *_Nullable error);
  71. /**
  72. * Callback type for receiving |UIImage| objects from a |GMSPlacePhotoMetadata| object. If an error
  73. * occurred, |photo| will be nil and |error| will contain information about the error.
  74. * @param photo The |UIImage| which was loaded.
  75. * @param error The error that occurred, if any.
  76. *
  77. * @related GMSPlacesClient
  78. */
  79. typedef void (^GMSPlacePhotoImageResultCallback)(UIImage *_Nullable photo,
  80. NSError *_Nullable error);
  81. /**
  82. * Main interface to the Places SDK. Used for searching and getting details about places. This class
  83. * should be accessed through the [GMSPlacesClient sharedClient] method.
  84. *
  85. * GMSPlacesClient methods should only be called from the main thread. Calling these methods from
  86. * another thread will result in an exception or undefined behavior. Unless otherwise specified, all
  87. * callbacks will be invoked on the main thread.
  88. */
  89. @interface GMSPlacesClient : NSObject
  90. /**
  91. * Provides the shared instance of GMSPlacesClient for the Google Places SDK for iOS, creating it if
  92. * necessary.
  93. *
  94. * If your application often uses methods of GMSPlacesClient it may want to hold onto this object
  95. * directly, as otherwise your connection to Google may be restarted on a regular basis.
  96. */
  97. + (instancetype)sharedClient;
  98. /**
  99. * Provides your API key to the Google Places SDK for iOS. This key is generated for your
  100. * application via the Google Cloud Platform Console, and is paired with your application's
  101. * bundle ID to identify it. This should be called by your application before using
  102. * GMSPlacesClient (e.g., in application:didFinishLaunchingWithOptions:).
  103. *
  104. * @return YES if the APIKey was successfully provided.
  105. */
  106. + (BOOL)provideAPIKey:(NSString *)key;
  107. /**
  108. * Returns the open source software license information for the Google Places SDK for iOS. This
  109. * information must be made available within your application.
  110. */
  111. + (NSString *)openSourceLicenseInfo;
  112. /**
  113. * Returns the version for this release of the Google Places SDK for iOS.. For example, "1.0.0".
  114. */
  115. + (NSString *)SDKVersion;
  116. /**
  117. * Returns the long version for this release of the Google Places SDK for iOS.. For example, "1.0.0
  118. * (102.1)".
  119. */
  120. + (NSString *)SDKLongVersion;
  121. /**
  122. * Get details for a place. This method is non-blocking.
  123. * @param placeID The place ID to lookup.
  124. * @param callback The callback to invoke with the lookup result.
  125. */
  126. - (void)lookUpPlaceID:(NSString *)placeID callback:(GMSPlaceResultCallback)callback;
  127. /**
  128. * Gets the metadata for up to 10 photos associated with a place.
  129. *
  130. * Photos are sourced from a variety of locations, including business owners and photos contributed
  131. * by Google+ users. In most cases, these photos can be used without attribution, or will have the
  132. * required attribution included as a part of the image. However, you must use the |attributions|
  133. * property in the response to retrieve any additional attributions required, and display those
  134. * attributions in your application wherever you display the image. A maximum of 10 photos are
  135. * returned.
  136. *
  137. * Multiple calls of this method will probably return the same photos each time. However, this is
  138. * not guaranteed because the underlying data may have changed.
  139. *
  140. * This method performs a network lookup.
  141. *
  142. * @param placeID The place ID for which to lookup photos.
  143. * @param callback The callback to invoke with the lookup result.
  144. */
  145. - (void)lookUpPhotosForPlaceID:(NSString *)placeID
  146. callback:(GMSPlacePhotoMetadataResultCallback)callback;
  147. /**
  148. * Loads the image for a specific photo at its maximum size.
  149. *
  150. * Image data may be cached by the SDK. If the requested photo does not exist in the cache then a
  151. * network lookup will be performed.
  152. *
  153. * @param photoMetadata The |GMSPlacePhotoMetadata| for which to load a |UIImage|.
  154. * @param callback The callback to invoke with the loaded |UIImage|.
  155. */
  156. - (void)loadPlacePhoto:(GMSPlacePhotoMetadata *)photoMetadata
  157. callback:(GMSPlacePhotoImageResultCallback)callback;
  158. /**
  159. * Loads the image for a specific photo, scaled to fit the given maximum dimensions.
  160. *
  161. * The image will be scaled to fit within the given dimensions while maintaining the aspect ratio of
  162. * the original image. This scaling is performed server-side.
  163. *
  164. * If the scale parameter is not 1.0 maxSize will be multiplied by this value and the returned
  165. * |UIImage| will be set to have the specified scale. This parameter should be set to the screen
  166. * scale if you are loading images for display on screen.
  167. *
  168. * Image data may be cached by the SDK. If the requested photo does not exist in the cache then a
  169. * network lookup will be performed.
  170. *
  171. * NOTE: After applying the scale factor the dimensions in maxSize will be rounded up to the nearest
  172. * integer before use. If an image is requested which is larger than the maximum size available a
  173. * smaller image may be returned.
  174. *
  175. * @param photoMetadata The |GMSPlacePhotoMetadata| for which to load a |UIImage|.
  176. * @param maxSize The maximum size of the image.
  177. * @param scale The scale to load the image at.
  178. * @param callback The callback to invoke with the loaded |UIImage|.
  179. */
  180. - (void)loadPlacePhoto:(GMSPlacePhotoMetadata *)photoMetadata
  181. constrainedToSize:(CGSize)maxSize
  182. scale:(CGFloat)scale
  183. callback:(GMSPlacePhotoImageResultCallback)callback;
  184. /**
  185. * Returns an estimate of the place where the device is currently known to be located.
  186. *
  187. * Generates a place likelihood list based on the device's last estimated location. The supplied
  188. * callback will be invoked with this likelihood list upon success and an NSError upon an error.
  189. *
  190. * NOTE: This method requires that your app has permission to access the current device location.
  191. * Before calling this make sure to request access to the users location using [CLLocationManager
  192. * requestWhenInUseAuthorization] or [CLLocationManager requestAlwaysAuthorization]. If you do call
  193. * this method and your app does not have the correct authorization status, the callback will be
  194. * called with an error.
  195. *
  196. * @param callback The callback to invoke with the place likelihood list.
  197. */
  198. - (void)currentPlaceWithCallback:(GMSPlaceLikelihoodListCallback)callback;
  199. /**
  200. * Find Autocomplete predictions from text query. Results may optionally be biased towards a
  201. * certain location or restricted to an area. This method is non-blocking.
  202. *
  203. * The supplied callback will be invoked with an array of autocompletion predictions upon success
  204. * and an NSError upon an error.
  205. *
  206. * @param query The partial text to autocomplete.
  207. * @param filter The filter to apply to the results. This parameter may be nil.
  208. * @param sessionToken The |GMSAutocompleteSessionToken| to associate request to a billing session.
  209. * @param callback The callback to invoke with the predictions.
  210. */
  211. - (void)findAutocompletePredictionsFromQuery:(NSString *)query
  212. filter:(nullable GMSAutocompleteFilter *)filter
  213. sessionToken:(nullable GMSAutocompleteSessionToken *)sessionToken
  214. callback:(GMSAutocompletePredictionsCallback)callback;
  215. /**
  216. * Fetch details for a place. This method is non-blocking.
  217. * @param placeID The place ID to lookup.
  218. * @param placeFields The individual place fields requested for the place objects in the list.
  219. * @param sessionToken The |GMSAutocompleteSessionToken| to associate request to a billing session.
  220. * @param callback The callback to invoke with the lookup result.
  221. */
  222. - (void)fetchPlaceFromPlaceID:(NSString *)placeID
  223. placeFields:(GMSPlaceField)placeFields
  224. sessionToken:(nullable GMSAutocompleteSessionToken *)sessionToken
  225. callback:(GMSPlaceResultCallback)callback;
  226. /**
  227. * Find place likelihoods using the user's current location. This method is non-blocking.
  228. *
  229. * The supplied callback will be invoked with an array of places with likelihood scores upon success
  230. * and an NSError upon an error.
  231. *
  232. * @param placeFields The individual place fields requested for the place objects in the list.
  233. * @param callback The callback to invoke with place likelihoods.
  234. */
  235. - (void)findPlaceLikelihoodsFromCurrentLocationWithPlaceFields:(GMSPlaceField)placeFields
  236. callback:
  237. (GMSPlaceLikelihoodsCallback)callback;
  238. @end
  239. NS_ASSUME_NONNULL_END