@@ -15,6 +15,8 @@ A customizable React Native TextInput component for Google Places Autocomplete u
1515- TypeScript support
1616- Session token support for reduced billing costs
1717- Extended place details fetching (Optional)
18+ - Compatible with both Expo and non-Expo projects
19+ - Works with Expo Web
1820
1921## Preview
2022
@@ -32,6 +34,8 @@ npm install react-native-google-places-textinput
3234yarn add react-native-google-places-textinput
3335```
3436
37+ > ** Note:** This package works seamlessly with both Expo and non-Expo React Native projects with no additional configuration required.
38+
3539## Prerequisites
3640
37411 . ** Enable the Places API (New)** in your Google Cloud Project
@@ -53,28 +57,17 @@ const YourComponent = () => {
5357 console .log (' Selected place:' , place);
5458 };
5559
56- const basicStyles = {
57- container: {
58- width: ' 100%' , // Ensure full width
59- paddingHorizontal: 16 ,
60- },
61- input: {
62- height: 40 , // Comfortable touch target
63- }
64- };
65-
6660 return (
6761 < GooglePlacesTextInput
6862 apiKey= " YOUR_GOOGLE_PLACES_API_KEY"
6963 onPlaceSelect= {handlePlaceSelect}
70- style= {basicStyles}
7164 / >
7265 );
7366};
7467```
7568
7669<details >
77- <summary >Example with Places API Configuration </summary >
70+ <summary >Example with language and region codes filtering </summary >
7871
7972``` javascript
8073const ConfiguredExample = () => {
@@ -97,7 +90,7 @@ const ConfiguredExample = () => {
9790</details >
9891
9992<details >
100- <summary >Example with Full Styling </summary >
93+ <summary >Example with full styling </summary >
10194
10295``` javascript
10396const StyledExample = () => {
@@ -153,41 +146,7 @@ const StyledExample = () => {
153146</details >
154147
155148<details >
156- <summary >Example Using Session Token</summary >
157-
158- ``` javascript
159- import { useRef } from ' react' ;
160-
161- const SessionTokenExample = () => {
162- const inputRef = useRef (null );
163-
164- const handlePlaceSelect = (place , sessionToken ) => {
165- console .log (' Selected place:' , place);
166- console .log (' Session token used:' , sessionToken);
167-
168- // You can now use this same sessionToken when fetching place details
169- // to benefit from reduced billing (session matching)
170- fetchPlaceDetails (place .placeId , sessionToken);
171- };
172-
173- const fetchPlaceDetails = async (placeId , sessionToken ) => {
174- // Your code to fetch place details using the same sessionToken
175- // ...
176- };
177-
178- return (
179- < GooglePlacesTextInput
180- ref= {inputRef}
181- apiKey= " YOUR_GOOGLE_PLACES_API_KEY"
182- onPlaceSelect= {handlePlaceSelect}
183- / >
184- );
185- };
186- ```
187- </details >
188-
189- <details >
190- <summary >Example with Place Details Fetching</summary >
149+ <summary >Example with place details fetching</summary >
191150
192151``` javascript
193152const PlaceDetailsExample = () => {
@@ -196,10 +155,7 @@ const PlaceDetailsExample = () => {
196155
197156 // Access detailed place information
198157 if (place .details ) {
199- console .log (' Address components:' , place .details .addressComponents );
200- console .log (' Geometry:' , place .details .geometry );
201- console .log (' Photos:' , place .details .photos );
202- // And other fields you requested
158+ console .log (place .details );
203159 }
204160 };
205161
@@ -214,12 +170,11 @@ const PlaceDetailsExample = () => {
214170 onError= {handleError}
215171 fetchDetails= {true }
216172 detailsFields= {[
217- ' address_components ' ,
218- ' formatted_address ' ,
219- ' geometry ' ,
173+ ' addressComponents ' ,
174+ ' formattedAddress ' ,
175+ ' location ' ,
220176 ' viewport' ,
221177 ' photos' ,
222- ' place_id' ,
223178 ' types'
224179 ]}
225180 / >
@@ -248,7 +203,7 @@ const PlaceDetailsExample = () => {
248203| ** Place Details Configuration** |
249204| fetchDetails | boolean | No | false | Automatically fetch place details when a place is selected |
250205| detailsProxyUrl | string | No | null | Custom proxy URL for place details requests |
251- | detailsFields | string[ ] | No | [ ] | Array of fields to include in the place details response |
206+ | detailsFields | string[ ] | No | [ 'displayName', 'formattedAddress', 'location', 'id' ] | Array of fields to include in the place details response. see [ Valid Fields ] ( https://developers.google.com/maps/documentation/places/web-service/place-details#fieldmask ) |
252207| ** UI Customization** |
253208| style | StyleProp | No | {} | Custom styles object |
254209| showLoadingIndicator | boolean | No | true | Show/hide loading indicator |
@@ -268,7 +223,7 @@ You can automatically fetch detailed place information when a user selects a pla
268223< GooglePlacesTextInput
269224 apiKey= " YOUR_GOOGLE_PLACES_API_KEY"
270225 fetchDetails= {true }
271- detailsFields= {[' formatted_address ' , ' geometry ' , ' viewport' , ' photos' ]}
226+ detailsFields= {[' formattedAddress ' , ' location ' , ' viewport' , ' photos' ]}
272227 onPlaceSelect= {(place ) => console .log (place .details )}
273228/ >
274229```
0 commit comments