|
| 1 | +// |
| 2 | +// GMSAutocompleteFetcher.h |
| 3 | +// Google Places API for iOS |
| 4 | +// |
| 5 | +// Copyright 2016 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 | + |
| 11 | +#if __has_feature(modules) |
| 12 | +@import GoogleMapsBase; |
| 13 | +#else |
| 14 | +#import <GoogleMapsBase/GoogleMapsBase.h> |
| 15 | +#endif |
| 16 | +#if __has_feature(modules) |
| 17 | +@import GoogleMapsBase; |
| 18 | +#else |
| 19 | +#import <GoogleMapsBase/GoogleMapsBase.h> |
| 20 | +#endif |
| 21 | +#import <GooglePlaces/GMSAutocompleteFilter.h> |
| 22 | + |
| 23 | +@class GMSAutocompletePrediction; |
| 24 | + |
| 25 | +GMS_ASSUME_NONNULL_BEGIN |
| 26 | + |
| 27 | +/** |
| 28 | + * Protocol for objects that can receive callbacks from GMSAutocompleteFetcher |
| 29 | + */ |
| 30 | +@protocol GMSAutocompleteFetcherDelegate <NSObject> |
| 31 | + |
| 32 | +@required |
| 33 | + |
| 34 | +/** |
| 35 | + * Called when autocomplete predictions are available. |
| 36 | + * @param predictions an array of GMSAutocompletePrediction objects. |
| 37 | + */ |
| 38 | +- (void)didAutocompleteWithPredictions:(GMS_NSArrayOf(GMSAutocompletePrediction *) *)predictions; |
| 39 | + |
| 40 | +/** |
| 41 | + * Called when an autocomplete request returns an error. |
| 42 | + * @param error the error that was received. |
| 43 | + */ |
| 44 | +- (void)didFailAutocompleteWithError:(NSError *)error; |
| 45 | + |
| 46 | +@end |
| 47 | + |
| 48 | +/** |
| 49 | + * GMSAutocompleteFetcher is a wrapper around the lower-level autocomplete APIs that encapsulates |
| 50 | + * some of the complexity of requesting autocomplete predictions as the user is typing. Calling |
| 51 | + * sourceTextHasChanged will generally result in the provided delegate being called with |
| 52 | + * autocomplete predictions for the queried text, with the following provisos: |
| 53 | + * |
| 54 | + * - The fetcher may not necessarily request predictions on every call of sourceTextHasChanged if |
| 55 | + * several requests are made within a short amount of time. |
| 56 | + * - The delegate will only be called with prediction results if those predictions are for the |
| 57 | + * text supplied in the most recent call to sourceTextHasChanged. |
| 58 | + */ |
| 59 | +@interface GMSAutocompleteFetcher : NSObject |
| 60 | + |
| 61 | +/** |
| 62 | + * Initialise the fetcher |
| 63 | + * @param bounds The bounds used to bias the results. This is not a hard restrict - places may still |
| 64 | + * be returned outside of these bounds. This parameter may be nil. |
| 65 | + * @param filter The filter to apply to the results. This parameter may be nil. |
| 66 | + */ |
| 67 | +- (instancetype)initWithBounds:(GMSCoordinateBounds *GMS_NULLABLE_PTR)bounds |
| 68 | + filter:(GMSAutocompleteFilter *GMS_NULLABLE_PTR)filter |
| 69 | + NS_DESIGNATED_INITIALIZER; |
| 70 | + |
| 71 | +/** Delegate to be notified with autocomplete prediction results. */ |
| 72 | +@property(nonatomic, weak) id<GMSAutocompleteFetcherDelegate> GMS_NULLABLE_PTR delegate; |
| 73 | + |
| 74 | +/** Bounds used to bias the autocomplete search (can be nil). */ |
| 75 | +@property(nonatomic, strong) GMSCoordinateBounds *GMS_NULLABLE_PTR autocompleteBounds; |
| 76 | + |
| 77 | +/** Filter to apply to autocomplete suggestions (can be nil). */ |
| 78 | +@property(nonatomic, strong) GMSAutocompleteFilter *GMS_NULLABLE_PTR autocompleteFilter; |
| 79 | + |
| 80 | +/** |
| 81 | + * Notify the fetcher that the source text to autocomplete has changed. |
| 82 | + * |
| 83 | + * This method should only be called from the main thread. Calling this method from another thread |
| 84 | + * will result in undefined behavior. Calls to |GMSAutocompleteFetcherDelegate| methods will also be |
| 85 | + * called on the main thread. |
| 86 | + * |
| 87 | + * This method is non-blocking. |
| 88 | + * @param text The partial text to autocomplete. |
| 89 | + */ |
| 90 | +- (void)sourceTextHasChanged:(NSString *GMS_NULLABLE_PTR)text; |
| 91 | + |
| 92 | +@end |
| 93 | + |
| 94 | +GMS_ASSUME_NONNULL_END |
0 commit comments