Skip to content

Commit 7887740

Browse files
committed
docs: update README and examples to clarify on place details fetching
1 parent 62e13c2 commit 7887740

File tree

3 files changed

+66
-64
lines changed

3 files changed

+66
-64
lines changed

README.md

Lines changed: 13 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -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
3234
yarn 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

3741
1. **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
8073
const 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
10396
const 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
193152
const 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
```

example/App.js

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,55 @@ const App = () => {
8989
types={['restaurant', 'cafe']}
9090
/>
9191
</View>
92+
93+
<View style={styles.section}>
94+
<Text style={styles.sectionTitle}>Place Details Example</Text>
95+
<GooglePlacesTextInput
96+
apiKey="YOUR_API_KEY_HERE"
97+
placeHolderText="Search with full details"
98+
onPlaceSelect={(place) => {
99+
console.log('Place with details:', place);
100+
if (place?.details) {
101+
console.log(
102+
'Address components:',
103+
place.details.addressComponents
104+
);
105+
console.log('Formatted address:', place.details.formattedAddress);
106+
console.log('Location:', place.details.location);
107+
console.log('Has photos:', place.details.photos?.length > 0);
108+
}
109+
}}
110+
onError={(error) => console.error('Places API error:', error)}
111+
fetchDetails={true}
112+
detailsFields={[
113+
'addressComponents',
114+
'formattedAddress',
115+
'location',
116+
'viewport',
117+
'photos',
118+
'types',
119+
]}
120+
style={{
121+
container: {
122+
width: '100%',
123+
paddingHorizontal: 16,
124+
},
125+
input: {
126+
height: 50,
127+
borderWidth: 1.5,
128+
borderColor: '#7986CB',
129+
borderRadius: 12,
130+
paddingHorizontal: 16,
131+
fontSize: 16,
132+
backgroundColor: '#F5F7FF',
133+
},
134+
suggestionsContainer: {
135+
borderRadius: 12,
136+
maxHeight: 300,
137+
},
138+
}}
139+
/>
140+
</View>
92141
</SafeAreaView>
93142
);
94143
};

package.json

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,13 @@
5050
"android",
5151
"autocomplete",
5252
"geolocation",
53-
"google",
54-
"google-places-api",
53+
"google-places",
5554
"ios",
56-
"place-autocomplete",
55+
"places-autocomplete",
5756
"places",
5857
"react-native",
59-
"react-native-component",
60-
"search",
61-
"textinput"
58+
"textinput",
59+
"expo"
6260
],
6361
"repository": {
6462
"type": "git",

0 commit comments

Comments
 (0)