GMSPlacesClient.h 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. //
  2. // GMSPlacesClient.h
  3. // Google Maps SDK for iOS
  4. //
  5. // Copyright 2014 Google Inc.
  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 <GoogleMaps/GMSPlace.h>
  12. #import <GoogleMaps/GMSPlacesMacros.h>
  13. #import <GoogleMaps/GMSUserAddedPlace.h>
  14. @class GMSAutocompleteFilter;
  15. @class GMSPlaceLikelihoodList;
  16. GMS_ASSUME_NONNULL_BEGIN
  17. /* Error domain used for Places API errors. */
  18. extern NSString * const kGMSPlacesErrorDomain;
  19. /* Error codes for |kGMSPlacesErrorDomain|. */
  20. typedef NS_ENUM(NSInteger, GMSPlacesErrorCode) {
  21. /**
  22. * Something went wrong with the connection to the Places API server.
  23. */
  24. kGMSPlacesNetworkError = -1,
  25. /**
  26. * The Places API server returned a response that we couldn't understand.
  27. */
  28. kGMSPlacesServerError = -2,
  29. /**
  30. * An internal error occurred in the Places API library.
  31. */
  32. kGMSPlacesInternalError = -3,
  33. /**
  34. * Operation failed due to an invalid (malformed or missing) API key.
  35. * <p>
  36. * See the <a href="https://developers.google.com/places/ios/start">developer's guide</a>
  37. * for information on creating and using an API key.
  38. */
  39. kGMSPlacesKeyInvalid = -4,
  40. /**
  41. * Operation failed due to an expired API key.
  42. * <p>
  43. * See the <a href="https://developers.google.com/places/ios/start">developer's guide</a>
  44. * for information on creating and using an API key.
  45. */
  46. kGMSPlacesKeyExpired = -5,
  47. /**
  48. * Operation failed due to exceeding the quota usage limit.
  49. * <p>
  50. * See the <a href="https://developers.google.com/places/ios/usage">developer's guide</a>
  51. * for information on usage limits and how to request a higher limit.
  52. */
  53. kGMSPlacesUsageLimitExceeded = -6,
  54. /**
  55. * Operation failed due to exceeding the usage rate limit for the API key.
  56. * <p>
  57. * This status code shouldn't be returned during normal usage of the API. It relates to usage of
  58. * the API that far exceeds normal request levels.
  59. */
  60. kGMSPlacesRateLimitExceeded = -7,
  61. /**
  62. * Operation failed due to exceeding the per-device usage rate limit.
  63. * <p>
  64. * This status code shouldn't be returned during normal usage of the API. It relates to usage of
  65. * the API that far exceeds normal request levels.
  66. */
  67. kGMSPlacesDeviceRateLimitExceeded = -8,
  68. /**
  69. * The Places API is not enabled.
  70. * <p>
  71. * See the <a href="https://developers.google.com/places/ios/start">developer's guide</a> for how
  72. * to enable the Google Places API for iOS.
  73. */
  74. kGMSPlacesAccessNotConfigured = -9,
  75. /**
  76. * The application's bundle identifier does not match one of the allowed iOS applications for the
  77. * API key.
  78. * <p>
  79. * See the <a href="https://developers.google.com/places/ios/start">developer's guide</a>
  80. * for how to configure bundle restrictions on API keys.
  81. */
  82. kGMSPlacesIncorrectBundleIdentifier = -10
  83. };
  84. /**
  85. * @relates GMSPlacesClient
  86. * Callback type for receiving place details lookups. If an error occurred,
  87. * |result| will be nil and |error| will contain information about the error.
  88. * @param result The |GMSPlace| that was returned.
  89. * @param error The error that occured, if any.
  90. */
  91. typedef void (^GMSPlaceResultCallback)(
  92. GMSPlace * GMS_NULLABLE_PTR result,
  93. NSError * GMS_NULLABLE_PTR error);
  94. /**
  95. * @relates GMSPlacesClient
  96. * Callback type for receiving place likelihood lists. If an error occurred, |likelihoodList| will
  97. * be nil and |error| will contain information about the error.
  98. * @param likelihoodList The list of place likelihoods.
  99. * @param error The error that occured, if any.
  100. */
  101. typedef void (^GMSPlaceLikelihoodListCallback)(
  102. GMSPlaceLikelihoodList * GMS_NULLABLE_PTR likelihoodList,
  103. NSError * GMS_NULLABLE_PTR error);
  104. /**
  105. * @relates GMSPlacesClient
  106. * Callback type for receiving autocompletion results. |results| is an array of
  107. * GMSAutocompletePredictions representing candidate completions of the query.
  108. * @param results An array of |GMSAutocompletePrediction|s.
  109. * @param error The error that occured, if any.
  110. */
  111. typedef void (^GMSAutocompletePredictionsCallback)(
  112. NSArray * GMS_NULLABLE_PTR results,
  113. NSError * GMS_NULLABLE_PTR error);
  114. /**
  115. * Main interface to the Places API. Used for searching and getting details about places. This class
  116. * should be accessed through the [GMSPlacesClient sharedClient] method.
  117. *
  118. * GMSPlacesClient methods should only be called from the main thread. Calling these methods from
  119. * another thread will result in an exception or undefined behavior. Unless otherwise specified, all
  120. * callbacks will be invoked on the main thread.
  121. */
  122. @interface GMSPlacesClient : NSObject
  123. /**
  124. * Provides the shared instance of GMSPlacesClient for the Google Maps SDK for iOS,
  125. * creating it if necessary.
  126. *
  127. * If your application often uses methods of GMSPlacesClient it may want to hold
  128. * onto this object directly, as otherwise your connection to Google may be restarted
  129. * on a regular basis.
  130. */
  131. + (instancetype)sharedClient;
  132. /**
  133. * Report that the device is at a particular place.
  134. */
  135. - (void)reportDeviceAtPlaceWithID:(NSString *)placeID;
  136. /**
  137. * Get details for a place. This method is non-blocking.
  138. * @param placeID The place ID to lookup.
  139. * @param callback The callback to invoke with the lookup result.
  140. */
  141. - (void)lookUpPlaceID:(NSString *)placeID callback:(GMSPlaceResultCallback)callback;
  142. /**
  143. * Returns an estimate of the place where the device is currently known to be located.
  144. *
  145. * Generates a place likelihood list based on the device's last estimated location. The supplied
  146. * callback will be invoked with this likelihood list upon success and an NSError upon an error.
  147. * @param callback The callback to invoke with the place likelihood list.
  148. */
  149. - (void)currentPlaceWithCallback:(GMSPlaceLikelihoodListCallback)callback;
  150. /**
  151. * Autocompletes a given text query. Results may optionally be biased towards a certain location.
  152. * The supplied callback will be invoked with an array of autocompletion predictions upon success
  153. * and an NSError upon an error.
  154. * @param query The partial text to autocomplete.
  155. * @param bounds The bounds used to bias the results. This is not a hard restrict - places may still
  156. * be returned outside of these bounds. This parameter may be nil.
  157. * @param filter The filter to apply to the results. This parameter may be nil.
  158. * @param callback The callback to invoke with the predictions.
  159. */
  160. - (void)autocompleteQuery:(NSString *)query
  161. bounds:(GMSCoordinateBounds * GMS_NULLABLE_PTR)bounds
  162. filter:(GMSAutocompleteFilter * GMS_NULLABLE_PTR)filter
  163. callback:(GMSAutocompletePredictionsCallback)callback;
  164. /**
  165. * Add a place. The |place| must have all its fields set, except that website or phoneNumber may be
  166. * nil.
  167. * @param place The details of the place to be added.
  168. * @param callback The callback to invoke with the place that was added.
  169. */
  170. - (void)addPlace:(GMSUserAddedPlace *)place
  171. callback:(GMSPlaceResultCallback)callback;
  172. @end
  173. GMS_ASSUME_NONNULL_END