forked from tolu360/react-native-google-places
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.d.ts
646 lines (596 loc) · 21.7 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
declare module "react-native-google-places" {
/**
* 2D Coordinate bounds for view boxes etc, as defined by the bottom left and
* top right corners.
*
* There isn't a direct correspondence between this type and native types.
*/
export interface GeoCoordinateBounds {
latitudeSW: number;
longitudeSW: number;
latitudeNE: number;
longitudeNE: number;
}
/**
* Standard cross-platform coordinate type.
*
* Corresponds to [CLLocationCoordinate2D](https://developer.apple.com/documentation/corelocation/cllocationcoordinate2d)
* and [LatLng](https://developers.google.com/android/reference/com/google/android/gms/maps/model/LatLng).
*/
export interface LatLng {
longitude: number;
latitude: number;
}
/**
* Current place, with additional likelihood property.
*
* Corresponds roughly to
* [GMSPlaceLikelihood](https://developers.google.com/places/ios-sdk/reference/interface_g_m_s_place_likelihood.html#a370caf145921ced6374bd39212561d90)
* and [com.google.android.libraries.places.api.net.PlaceLikelihood](https://developers.google.com/places/android-sdk/reference/com/google/android/libraries/places/api/model/PlaceLikelihood),
* though the likelihood has been flattened into the Place object.
*/
export interface CurrentPlace extends GMSTypes.Place {
/**
* Returns a value from 0.0 to 1.0 indicating the confidence that the user
* is at this place.
*
* The larger the value the more confident we are of the place returned. For
* example, a likelihood of 0.75 means that the user is at least 75% likely
* to be at this place.
*/
likelihood: number;
}
/**
* Internal mappings to Google Maps Services types.
*/
export namespace GMSTypes {
/**
* Internal mapping to [GMSPlace](https://developers.google.com/places/ios-sdk/reference/interface_g_m_s_place)
* and [com.google.android.libraries.places.api.model.Place](https://developers.google.com/places/android-sdk/reference/com/google/android/libraries/places/api/model/Place).
*
* Represents a particular physical space.
*
* A Place encapsulates information about a physical location, including
* its name, address, and any other information we might have about it.
*/
export interface Place {
/**
* Name of the place.
*/
name: string;
/**
* Place ID of this place.
*
* For more information: [Place IDs](https://developers.google.com/places/place-id)
*/
placeID: string;
/**
* The Plus code representation of location for this place.
*/
plusCode: PlusCode;
/**
* Location of the place.
*
* Corresponds to [coordinates](https://developers.google.com/places/ios-sdk/reference/interface_g_m_s_place.html#a3dc43865df0de69b6b1203a15a745efc)
* and [getLatLng](https://developers.google.com/places/android-sdk/reference/com/google/android/libraries/places/api/model/Place.html#getLatLng()).
*/
location: LatLng;
/**
* The Opening Hours information for this place.
*
* The mapping only contains the weekday text, i.e.
* [GMSOpeningHours#weekdayTest](https://developers.google.com/places/ios-sdk/reference/interface_g_m_s_opening_hours.html#a6a4cd04495230795fcd04d814c71d107)
* and [OpeningHours#getWeekdayTest](https://developers.google.com/places/android-sdk/reference/com/google/android/libraries/places/api/model/OpeningHours.html#getWeekdayText()).
*/
openingHours: string[];
/**
* Phone number of this place, in international format, i.e. including the
* country code prefixed with "+". For example, Google Sydney's phone
* number is "+61 2 9374 4000".
*/
phoneNumber: string;
/**
* Simple address of the Place.
*
* Corresponds to [formattedAddress](https://developers.google.com/places/ios-sdk/reference/interface_g_m_s_place.html#a8926a762ae78bcd18c0ea126d270ef3d)
* and [getAddress](https://developers.google.com/places/android-sdk/reference/com/google/android/libraries/places/api/model/Place.html#getAddress())
*/
address: string;
/**
* Five-star rating for this place based on user reviews.
*
* Ratings range from 1.0 to 5.0. 0.0 means we have no rating for this
* place (e.g. because not enough users have reviewed this place).
*/
rating: number;
/**
* Represents how many reviews make up this place's rating.
*/
userRatingsTotal: number;
/**
* Price level for this place, as integers from 0 to 4.
*
* e.g. A value of 4 means this place is "$$$$" (expensive). A value of 0
* means free (such as a museum with free admission).
*/
priceLevel: any;
/**
* The types of this place.
*/
types: ReturnPlaceType[];
/**
* Website for this place.
*
* This is the URI of the website maintained by the Place, if available.
* This link is always for a third-party website not affiliated with the
* Places API.
*
* Corresponds to [website](https://developers.google.com/places/ios-sdk/reference/interface_g_m_s_place.html#a7b9ee24d284ac279eed7f83a838354fe)
* and [getWebsiteUri](https://developers.google.com/places/android-sdk/reference/com/google/android/libraries/places/api/model/Place.html#getWebsiteUri()).
*/
website: string;
/**
* This returns a viewport of a size that is suitable for displaying this
* place. For example, a Place object representing a store may have a
* relatively small viewport, while a Place object representing a country
* may have a very large viewport.
*/
viewport: GeoCoordinateBounds;
/**
* Address components. If you need the full address, consider using
* `address` instead.
*/
addressComponents: Array<AddressComponent>;
}
/**
* Internal mapping to [GMSPlusCode](https://developers.google.com/places/ios-sdk/reference/interface_g_m_s_place)
* and [com.google.android.libraries.places.api.model.PlusCode](https://developers.google.com/places/android-sdk/reference/com/google/android/libraries/places/api/model/PlusCode).
*
* A class containing the Plus codes representation for a location.
*
* Plus Code, or Open Location Code (OLC), is a geocode system for
* identifying any geographical area on Earth, even when a street address
* does not exist.
*
* See https://plus.codes/ for more details.
*/
export interface PlusCode {
/**
* Geo plus code, e.g.
* "8FVC9G8F+5W"
*/
globalCode: string;
/**
* Compound plus code, e.g.
* "9G8F+5W Zurich, Switzerland"
*/
compoundCode: string;
}
/**
* Place Type, corresponding to the
* [return types table 1](https://developers.google.com/places/ios-sdk/supported_types).
*
* You can use the following values in the `types` filter for place
* [searches](https://developers.google.com/places/web-service/search)
* (Places API only). These types may also be returned anywhere a Place
* result is returned (for example as part of the
* [Place Details](https://developers.google.com/places/android-sdk/place-details)
* resulting from a call to `fetchPlace()`).
*/
export type PlaceType = "accounting"
| "airport"
| "amusement_park"
| "aquarium"
| "art_gallery"
| "atm"
| "bakery"
| "bank"
| "bar"
| "beauty_salon"
| "bicycle_store"
| "book_store"
| "bowling_alley"
| "bus_station"
| "cafe"
| "campground"
| "car_dealer"
| "car_rental"
| "car_repair"
| "car_wash"
| "casino"
| "cemetery"
| "church"
| "city_hall"
| "clothing_store"
| "convenience_store"
| "courthouse"
| "dentist"
| "department_store"
| "doctor"
| "electrician"
| "electronics_store"
| "embassy"
| "fire_station"
| "florist"
| "funeral_home"
| "furniture_store"
| "gas_station"
| "gym"
| "hair_care"
| "hardware_store"
| "hindu_temple"
| "home_goods_store"
| "hospital"
| "insurance_agency"
| "jewelry_store"
| "laundry"
| "lawyer"
| "library"
| "liquor_store"
| "local_government_office"
| "locksmith"
| "lodging"
| "meal_delivery"
| "meal_takeaway"
| "mosque"
| "movie_rental"
| "movie_theater"
| "moving_company"
| "museum"
| "night_club"
| "painter"
| "park"
| "parking"
| "pet_store"
| "pharmacy"
| "physiotherapist"
| "plumber"
| "police"
| "post_office"
| "real_estate_agency"
| "restaurant"
| "roofing_contractor"
| "rv_park"
| "school"
| "shoe_store"
| "shopping_mall"
| "spa"
| "stadium"
| "storage"
| "store"
| "subway_station"
| "supermarket"
| "synagogue"
| "taxi_stand"
| "train_station"
| "transit_station"
| "travel_agency"
| "veterinary_care"
| "zoo";
/**
* Place Type, corresponding to the
* [return types table 2](https://developers.google.com/places/ios-sdk/supported_types).
*
* The following types may be returned anywhere a Place result is returned
* (for example a [Find Place](https://developers.google.com/places/web-service/search#FindPlaceRequests)
* request), in addition to the types in table 1 above. These types are also
* used for address components.
*
* For more details on these types, refer to
* [Address Types](https://developers.google.com/maps/documentation/geocoding/intro#Types).
*
* Note: The types below are not supported in the type filter of a place
* search.
*/
export type ReadOnlyPlaceType = "administrative_area_level_1"
| "administrative_area_level_2"
| "administrative_area_level_3"
| "administrative_area_level_4"
| "administrative_area_level_5"
| "colloquial_area"
| "country"
| "establishment"
| "finance"
| "floor"
| "food"
| "general_contractor"
| "geocode"
| "health"
| "intersection"
| "locality"
| "natural_feature"
| "neighborhood"
| "place_of_worship"
| "political"
| "point_of_interest"
| "post_box"
| "postal_code"
| "postal_code_prefix"
| "postal_code_suffix"
| "postal_town"
| "premise"
| "room"
| "route"
| "street_address"
| "street_number"
| "sublocality"
| "sublocality_level_4"
| "sublocality_level_5"
| "sublocality_level_3"
| "sublocality_level_2"
| "sublocality_level_1"
| "subpremise";
/**
* All the different kinds of place types that the Places API can return.
*/
export type ReturnPlaceType = ReadOnlyPlaceType | PlaceType;
/**
* Place Type, corresponding to the
* [return types table 3](https://developers.google.com/places/ios-sdk/supported_types).
*
* You may restrict results from a Place Autocomplete request to be of a
* certain type by passing a `types` parameter. The parameter specifies a
* type or a type collection, as listed in the supported types below. If
* nothing is specified, all types are returned. In general only a single
* type is allowed. The exception is that you can safely mix the `geocode`
* and `establishment` types, but note that this will have the same effect
* as specifying no types.
*
* ## `geocode`
*
* Instructs the Place Autocomplete service to return only geocoding
* results, rather than business results. Generally, you use this request
* to disambiguate results where the location specified may be
* indeterminate.
*
* ## `address`
*
* Instructs the Place Autocomplete service to return only geocoding
* results with a precise address. Generally, you use this request when
* you know the user will be looking for a fully specified address.
*
* ## `establishment`
*
* Instructs the Place Autocomplete service to return only business
* results.
*
* ## `regions`
*
* Instructs the Places service to return any result matching the
* following types:
*
* - `locality` (PlaceType.Locality)
* - `sublocality` (PlaceType.SubLocality)
* - `postal_code` (PlaceType.PostalCode)
* - `country` (PlaceType.Country)
* - `administrative_area_level_1` (PlaceType.AdministrativeAreaLevel1)
* - `administrative_area_level_2` (PlaceType.AdministrativeAreaLevel2)
*
* ## `cities`
*
* Instructs the Places service to return results that match `locality`
* (PlaceType.Locality) or `administrative_area_level_3`
* (PlaceType.AdministrativeAreaLevel3).
*/
export type AutocompleteType = "geocode" | "address" | "establishment"
| "regions" | "cities";
/**
* Internal mapping to [AddressComponent](https://developers.google.com/places/ios-sdk/reference/interface_g_m_s_address_component)
* and [com.google.android.libraries.places.api.model.AddressComponent](https://developers.google.com/places/android-sdk/reference/com/google/android/libraries/places/api/model/AddressComponent).
*
* Represents a component of an address, e.g., street number, postcode,
* city, etc.
*/
export interface AddressComponent {
/**
* Type of the address component.
*/
types: ReturnPlaceType[];
/**
* Name of the address component, e.g. "Sydney".
*/
name: string;
/**
* Short name of the address component, e.g. "AU".
*/
shortName: string;
}
/**
* Internal mapping to [GMSAutocompletePrediction](https://developers.google.com/places/ios-sdk/reference/https://developers.google.com/places/ios-sdk/reference/interface_g_m_s_autocomplete_prediction)
* and [com.google.android.libraries.places.api.model.AutocompletePrediction](https://developers.google.com/places/android-sdk/reference/com/google/android/libraries/places/api/model/AutocompletePrediction).
*
* Represents an autocomplete suggestion of a place, based on a particular
* text query.
*
* An AutocompletePrediction includes the description of the suggested place
* as well as basic details including place ID and types.
*/
export interface AutocompletePrediction {
/**
* The full text of a place. This is a combination of the primary text
* and the secondary text.
*
* Example: "Eiffel Tower, Avenue Anatole France, Paris, France"
*/
fullText: string;
/**
* Returns the primary text of a place. This will usually be the name of
* the place.
*
* Example: "Eiffel Tower", "123 Pitt Street"
*/
primaryText: string;
/**
* Returns the secondary text of a place. This provides extra context on
* the place, and can be used as a second line when showing autocomplete
* predictions.
*
* Example: "Avenue Anatole France, Paris, France", "Sydney, New South
* Wales"
*/
secondaryText: string;
/**
* Returns the place ID of the place being referred to by this prediction.
*
* For more information: [Place IDs](https://developers.google.com/places/place-id)
*/
placeID: string;
/**
* The types of this autocomplete result.
*/
types?: ReturnPlaceType;
}
}
/**
* Google Places options.
*
* This type roughly corresponds to
* [GMSAutocompleteFilter](https://developers.google.com/places/ios-sdk/reference/interface_g_m_s_autocomplete_filter)
* and [com.google.android.libraries.places.widget.Autocomplete](https://developers.google.com/places/android-sdk/reference/com/google/android/libraries/places/widget/Autocomplete).
*/
export interface RNGooglePlacesNativeOptions {
/**
* The type of results to return.
*/
type: GMSTypes.AutocompleteType;
/**
* Limit results to a specific country using a
* [ISO 3166-1 Alpha-2 country code](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2)
* (case insensitive). If this is not set, no country filtering will take
* place.
*/
country: string;
/**
* If true, the autocomplete modal will
* [open as an overlay rather than fullscreen](https://developers.google.com/places/images/acw_overlay.png).
*
* Note: This property is Android only.
*/
useOverlay: boolean;
/**
* If present, the autocomplete modal would launch with results
* pre-populated for the query passed.
*
* Note: This property is Android only.
*/
initialQuery: string;
useSessionToken: boolean;
/**
* To bias autocomplete results to a specific geographic region.
*
* Note: On iOS, only one of locationBias or locationRestriction is
* respected, when passing both, only the first passed option would be used.
*/
locationBias: GeoCoordinateBounds;
/**
* To restrict autocomplete results to a specific geographic region.
*
* Note: On iOS, only one of locationBias or locationRestriction is
* respected, when passing both, only the first passed option would be used.
*/
locationRestriction: GeoCoordinateBounds;
}
class RNGooglePlacesNative {
public openAutocompleteModal<K extends keyof GMSTypes.Place>(
autocompleteFilter: RNGooglePlacesNativeOptions, placeFields: K[],
): Promise<Promise<Pick<GMSTypes.Place, (typeof placeFields)[number]>>>;
public getAutocompletePredictions(
query: string, filterOptions: RNGooglePlacesNativeOptions,
): Promise<GMSTypes.AutocompletePrediction[]>;
public lookUpPlaceByID<K extends keyof GMSTypes.Place>(
placeID: string, placeFields: K[]
): Promise<Pick<GMSTypes.Place, (typeof placeFields)[number]>>;
public getCurrentPlace<K extends keyof GMSTypes.Place>(
placeFields: K[]
): Promise<
Pick<CurrentPlace, (typeof placeFields)[number] | "likelihood">[]
>;
}
class RNGooglePlaces {
static optionsDefaults: {
type: '',
country: '',
useOverlay: false,
initialQuery: '',
useSessionToken: true,
locationBias: {
latitudeSW: 0,
longitudeSW: 0,
latitudeNE: 0,
longitudeNE: 0,
},
locationRestriction: {
latitudeSW: 0,
longitudeSW: 0,
latitudeNE: 0,
longitudeNE: 0,
}
};
static placeFieldsDefaults: (keyof GMSTypes.Place)[];
/**
* Note: To prevent yourself from incurring huge usage bill, you should
* select the result fields you need in your application.
*/
public openAutocompleteModal(
options?: Partial<RNGooglePlacesNativeOptions>,
): Promise<GMSTypes.Place>;
public openAutocompleteModal<K extends keyof GMSTypes.Place>(
options: Partial<RNGooglePlacesNativeOptions>, placeFields: K[],
): Promise<Pick<GMSTypes.Place, (typeof placeFields)[number]>>;
/**
* If you have specific branding needs or you would rather build out your
* own custom search input and suggestions list (think Uber), you should
* call these methods to call the native SDKs directly.
*/
public getAutocompletePredictions(
query: string, options?: Partial<RNGooglePlacesNativeOptions>,
): Promise<GMSTypes.AutocompletePrediction[]>;
/**
* For more information: [Place IDs](https://developers.google.com/places/place-id)
*/
public lookUpPlaceByID(placeID: string): Promise<GMSTypes.Place>;
/**
* For more information: [Place IDs](https://developers.google.com/places/place-id)
*/
public lookUpPlaceByID<K extends keyof GMSTypes.Place>(
placeID: string, placeFields: K[]
): Promise<Pick<GMSTypes.Place, (typeof placeFields)[number]>>;
/**
* This method returns to you the place where the device is currently
* located (that is, the place at the device's currently-reported location).
*
* For each place, the result includes an indication of the likelihood that
* the place is the right one. A higher value for likelihood means a greater
* probability that the place is the best match. Ensure you have required
* the appropriate permissions as stated post-install steps above before
* making this request.
*
* The sum of the likelihoods in a given result set is always less than or
* equal to 1.0.
*
* Note: To prevent yourself from incurring huge usage bill, you should
* select only the result fields you need in your application.
*/
public getCurrentPlace(): Promise<CurrentPlace[]>;
/**
* This method returns to you the place where the device is currently
* located (that is, the place at the device's currently-reported location).
*
* For each place, the result includes an indication of the likelihood that
* the place is the right one. A higher value for likelihood means a greater
* probability that the place is the best match. Ensure you have required
* the appropriate permissions as stated post-install steps above before
* making this request.
*
* The sum of the likelihoods in a given result set is always less than or
* equal to 1.0.
*/
public getCurrentPlace<K extends keyof GMSTypes.Place>(
placeFields: K[]
): Promise<
Pick<CurrentPlace, (typeof placeFields)[number] | "likelihood">[]
>;
}
const _: RNGooglePlaces;
export default _;
}