· 6 years ago · Jan 27, 2020, 08:12 AM
1<GooglePlacesAutocomplete
2 placeholder='Search or get your current location'
3 minLength={2} // minimum length of text to search
4 autoFocus={false}
5 fetchDetails={true}
6 onPress={(data, details = null) => { // 'details' is provided when fetchDetails = true
7 console.log(data);
8 console.log(details);
9 }}
10 getDefaultValue={() => {
11 return ''; // text input default value
12 }}
13 query={{
14 // available options: https://developers.google.com/places/web-service/autocomplete
15 key: 'AIzaSyCC8DuJiwmnfvfXzx4H9f_Rqt9WxP7s3iE',
16 language: 'en', // language of the results
17 types: '(cities)', // default: 'geocode'
18 }}
19 styles={{
20
21 containerTop: {
22 position: 'absolute',
23 top: 0,
24 left: 0,
25 right: 0,
26 alignItems: 'center',
27 justifyContent: 'flex-start',
28 },
29 horizontal: {
30 flexDirection: 'row',
31 justifyContent: 'space-around',
32 },
33 padding: { padding: 20 },
34 listView: {
35 elevation: 1,
36 backgroundColor: '#ffffff',
37 },
38 textInputContainer: {
39 borderBottomWidth: 0,
40 borderTopWidth: 0,
41 },
42 textInput: {
43 color: '#00539b',
44 fontSize: 16,
45 },
46 description: {
47 fontWeight: 'bold',
48 },
49 predefinedPlacesDescription: {
50 color: '#fede00',
51 },
52 }}
53
54 currentLocation={true} // Will add a 'Current location' button at the top of the predefined places list
55 currentLocationLabel="Current location"
56 nearbyPlacesAPI='GooglePlacesSearch' // Which API to use: GoogleReverseGeocoding or GooglePlacesSearch
57 GoogleReverseGeocodingQuery={{
58 // available options for GoogleReverseGeocoding API : https://developers.google.com/maps/documentation/geocoding/intro
59 }}
60 GooglePlacesSearchQuery={{
61 // available options for GooglePlacesSearch API : https://developers.google.com/places/web-service/search
62 rankby: 'distance',
63 types: 'food',
64 }}
65 GooglePlacesDetailsQuery={{
66 // available options for GooglePlacesDetails API : https://developers.google.com/places/web-service/details
67 fields: 'formatted_address',
68 }}
69
70 filterReverseGeocodingByTypes={['locality', 'administrative_area_level_3']} // filter the reverse geocoding results by types - ['locality', 'administrative_area_level_3'] if you want to display only cities
71
72
73 predefinedPlacesAlwaysVisible={true}
74 />