Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ const PlaceDetailsExample = () => {
| onBlur | (event: NativeSyntheticEvent<TextInputFocusEventData>) => void | No | - | Callback when input is blurred |
| **Search Configuration** |
| proxyUrl | string | No | - | Custom proxy URL for API requests (Required for Expo web) |
| proxyHeaders | object | No | - | Headers to pass to the proxy (ex. { Authorization: 'Bearer AUTHTOKEN' } ) |
| languageCode | string | No | - | Language code (e.g., 'en', 'fr') |
| includedRegionCodes | string[] | No | - | Array of region codes to filter results |
| types | string[] | No | [] | Array of place types to filter |
Expand All @@ -224,6 +225,7 @@ const PlaceDetailsExample = () => {
| **Place Details Configuration** |
| fetchDetails | boolean | No | false | Automatically fetch place details when a place is selected |
| detailsProxyUrl | string | No | null | Custom proxy URL for place details requests (Required on Expo web)|
| detailsProxyHeaders | object | No | - | Headers to pass to the place details proxy (ex. { Authorization: 'Bearer AUTHTOKEN' } ) |
| 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) |
| **UI Customization** |
| showLoadingIndicator | boolean | No | true | Show loading spinner during API requests |
Expand Down
7 changes: 7 additions & 0 deletions src/GooglePlacesTextInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ interface GooglePlacesTextInputProps extends TextInputInheritedProps {
value?: string;
placeHolderText?: string;
proxyUrl?: string;
proxyHeaders?: Record<string, string>;
languageCode?: string;
includedRegionCodes?: string[];
types?: string[];
Expand All @@ -118,6 +119,7 @@ interface GooglePlacesTextInputProps extends TextInputInheritedProps {
nestedScrollEnabled?: boolean;
fetchDetails?: boolean;
detailsProxyUrl?: string | null;
detailsProxyHeaders?: Record<string, string>;
detailsFields?: string[];
onError?: (error: any) => void;
enableDebug?: boolean;
Expand Down Expand Up @@ -145,6 +147,7 @@ const GooglePlacesTextInput = forwardRef<
value,
placeHolderText,
proxyUrl,
proxyHeaders = null,
languageCode,
includedRegionCodes,
types = [],
Expand All @@ -163,6 +166,7 @@ const GooglePlacesTextInput = forwardRef<
nestedScrollEnabled = true,
fetchDetails = false,
detailsProxyUrl = null,
detailsProxyHeaders = null,
detailsFields = [],
onError,
enableDebug = false,
Expand Down Expand Up @@ -271,6 +275,7 @@ const GooglePlacesTextInput = forwardRef<
text,
apiKey: apiKey ? '[PROVIDED]' : '[MISSING]', // ✅ Security fix
proxyUrl,
proxyHeaders,
sessionToken,
languageCode,
includedRegionCodes,
Expand All @@ -294,6 +299,7 @@ const GooglePlacesTextInput = forwardRef<
text,
apiKey,
proxyUrl,
proxyHeaders,
sessionToken,
languageCode,
includedRegionCodes,
Expand Down Expand Up @@ -330,6 +336,7 @@ const GooglePlacesTextInput = forwardRef<
placeId,
apiKey: apiKey ? '[PROVIDED]' : '[MISSING]', // ✅ Security fix
detailsProxyUrl,
detailsProxyHeaders,
sessionToken,
languageCode,
detailsFields,
Expand Down
16 changes: 16 additions & 0 deletions src/services/googlePlacesApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ interface FetchPredictionsParams {
text: string;
apiKey?: string;
proxyUrl?: string;
proxyHeaders?: Record<string, string> | null;
sessionToken?: string | null;
languageCode?: string;
includedRegionCodes?: string[];
Expand All @@ -17,6 +18,7 @@ interface FetchPlaceDetailsParams {
placeId: string;
apiKey?: string;
detailsProxyUrl?: string | null;
detailsProxyHeaders?: Record<string, string> | null;
sessionToken?: string | null;
languageCode?: string;
detailsFields?: string[];
Expand All @@ -39,6 +41,7 @@ export const fetchPredictions = async ({
text,
apiKey,
proxyUrl,
proxyHeaders,
sessionToken,
languageCode,
includedRegionCodes,
Expand All @@ -57,6 +60,12 @@ export const fetchPredictions = async ({
'Content-Type': 'application/json',
};

if (proxyUrl && proxyHeaders) {
Object.entries(proxyHeaders).forEach(([key, value]) => {
headers[key] = value;
});
}

if (apiKey) {
headers['X-Goog-Api-Key'] = apiKey;
}
Expand Down Expand Up @@ -96,6 +105,7 @@ export const fetchPlaceDetails = async ({
placeId,
apiKey,
detailsProxyUrl,
detailsProxyHeaders,
sessionToken,
languageCode,
detailsFields = [],
Expand All @@ -113,6 +123,12 @@ export const fetchPlaceDetails = async ({
'Content-Type': 'application/json',
};

if (detailsProxyUrl && detailsProxyHeaders) {
Object.entries(detailsProxyHeaders).forEach(([key, value]) => {
headers[key] = value;
});
}

if (apiKey) {
headers['X-Goog-Api-Key'] = apiKey;
}
Expand Down