lightweight React native google place autocomplete
Simulator.Screen.Recording.-.iPhone.17.Pro.-.2026-05-06.at.22.01.05.mov
yarn add react-native-place-autocompleteimport { View, StyleSheet, Text } from 'react-native';
import {
PlacesAutocomplete,
type SelectedPlace,
} from 'react-native-place-autocomplete';
import { SafeAreaProvider, SafeAreaView } from 'react-native-safe-area-context';
import { useState } from 'react';
export default function App() {
const [result, setResult] = useState<SelectedPlace | null>(null);
const onSelect = (place: SelectedPlace) => {
setResult(place);
};
return (
<SafeAreaProvider>
<SafeAreaView style={{ flex: 1, backgroundColor: '#fff' }}>
<View style={styles.container}>
<PlacesAutocomplete
apiKey={'YOUR_API_KEY'}
onSelect={onSelect}
placeholder="Adresse..."
minLength={2}
debounce={300}
/>
</View>
</SafeAreaView>
</SafeAreaProvider>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'flex-start',
backgroundColor: '#fff',
marginTop: 40,
marginHorizontal: 20,
},
});The PlacesAutocomplete component provides an autocomplete control for place searching using the Google Places API. Here is the detailed documentation of all available props.
- Type:
string - Required: β Yes
- Description: Authentication key for the Google Places API. This key is necessary to access autocomplete and place details services.
- Example:
<PlacesAutocomplete apiKey="YOUR_GOOGLE_PLACES_API_KEY" />
- Type:
(place: SelectedPlace) => void - Required: β Yes
- Description: Callback function called when the user selects a place from the suggestions list.
SelectedPlaceParameter:prediction: Prediction- The prediction data of the placedetails: Details- Complete details of the placeplaceId: string- The unique identifier of the placedescription: string- Description of the placemainText: string- Formatted main textsecondaryText: string- Secondary text (usually region/state)coordinates: { lat: number; lng: number }- GPS coordinates of the place
- Example:
<PlacesAutocomplete onSelect={(place) => { console.log('Selected place:', place); console.log('Coordinates:', place.coordinates); }} />
- Type:
number - Required: β Yes
- Description: Minimum number of characters the user must enter before the search is triggered.
- Default value:
2 - Example:
<PlacesAutocomplete minLength={3} />
- Type:
number - Required: β Yes
- Description: Delay in milliseconds before performing the search after the user stops typing. This helps reduce the number of API requests.
- Default value:
300 - Example:
<PlacesAutocomplete debounce={500} />
- Type:
StyleProp<ViewStyle> - Required: β No
- Description: Custom style for the main container of the component.
- Example:
<PlacesAutocomplete containerStyle={{ padding: 16, marginTop: 10 }} />
- Type:
StyleProp<ViewStyle> - Required: β No
- Description: Custom style for the input container (wrapper containing the left icon, input, and right icon).
- Example:
<PlacesAutocomplete inputContainerStyle={{ borderWidth: 1, borderColor: '#ccc', borderRadius: 8, }} />
- Type:
StyleProp<TextStyle> - Required: β No
- Description: Custom style for the TextInput field.
- Example:
<PlacesAutocomplete inputStyle={{ fontSize: 16, color: '#333', paddingVertical: 10, }} />
- Type:
StyleProp<ViewStyle> - Required: β No
- Description: Custom style for the places suggestions list.
- Example:
<PlacesAutocomplete listStyle={{ maxHeight: 300, borderRadius: 8, shadowColor: '#000', shadowOpacity: 0.1, elevation: 3, }} />
- Type:
StyleProp<TextStyle> - Required: β No
- Description: Custom style for text portions that match the user's search. These portions are highlighted in the suggestions list.
- Example:
<PlacesAutocomplete highlightedStyle={{ fontWeight: 'bold', color: '#10B981', }} />
-
Type:
ReactNode -
Required: β No
-
Description: Custom icon to display on the left side of the input. By default, a magnifying glass (π) is displayed.
-
Example:
import { MaterialCommunityIcons } from '@expo/vector-icons'; <PlacesAutocomplete leftIcon={<MaterialCommunityIcons name="magnify" size={24} />} />;
- Type:
ReactNode - Required: β No
- Description: Custom icon to display on the right side of the input when the input is not loading. By default, a cross (β) that clears the text is displayed.
- Example:
<PlacesAutocomplete rightIcon={<Text>π</Text>} />
-
Type:
ReactNode -
Required: β No
-
Description: Custom icon to display in each place suggestion. By default, a pin (π) is displayed.
-
Example:
import { MaterialCommunityIcons } from '@expo/vector-icons'; <PlacesAutocomplete pinIcon={ <MaterialCommunityIcons name="map-marker" size={20} color="white" /> } />;
- Type:
string - Required: β No
- Description: Background color for the pin icon container in each suggestion. Accepts standard CSS colors or hex values.
- Default value:
#F0FDF4(light green) - Example:
<PlacesAutocomplete pinIconBackgroundColor="#EFF6FF" />
- Type:
string - Required: β No
- Description: Placeholder text displayed in the input when it's empty.
- Example:
<PlacesAutocomplete placeholder="Enter an address..." />
- Type:
string - Required: β No
- Description: Color of the placeholder text. Inherited from
TextInputPropsin React Native. - Default value:
#9CA3AF(gray) - Example:
<PlacesAutocomplete placeholderTextColor="#B0B0B0" />
- Type:
string - Required: β No
- Description: Color of the loading indicator displayed while suggestions are being fetched.
- Default value:
#10B981(green) - Example:
<PlacesAutocomplete loadingColor="#3B82F6" />
The component extends TextInputProps from React Native, which means you can also use standard TextInput props:
editable- Enable/disable editingautoCapitalize- Auto capitalizationautoCorrect- Auto correctionreturnKeyType- Return key type (default: 'search')keyboardType- Keyboard typemaxLength- Maximum text lengthsecureTextEntry- Hide text- And all other available
TextInputprops
import { PlacesAutocomplete } from 'react-native-place-autocomplete';
import { View, Text } from 'react-native';
import { useState } from 'react';
export default function App() {
const [selectedPlace, setSelectedPlace] = useState(null);
return (
<View style={{ flex: 1, padding: 20 }}>
<PlacesAutocomplete
apiKey="YOUR_GOOGLE_PLACES_API_KEY"
minLength={2}
debounce={400}
placeholder="Search for an address..."
onSelect={(place) => {
setSelectedPlace(place);
console.log('Selected address:', place.description);
console.log('Coordinates:', place.coordinates);
}}
containerStyle={{ marginTop: 10 }}
inputContainerStyle={{
borderWidth: 1,
borderColor: '#ddd',
borderRadius: 8,
backgroundColor: '#fff',
}}
inputStyle={{ fontSize: 14 }}
listStyle={{ maxHeight: 300 }}
highlightedStyle={{ fontWeight: 'bold', color: '#10B981' }}
loadingColor="#10B981"
pinIconBackgroundColor="#E0F2FE"
placeholderTextColor="#9CA3AF"
/>
{selectedPlace && (
<View style={{ marginTop: 20 }}>
<Text style={{ fontSize: 16, fontWeight: 'bold' }}>
{selectedPlace.description}
</Text>
<Text>Latitude: {selectedPlace.coordinates.lat}</Text>
<Text>Longitude: {selectedPlace.coordinates.lng}</Text>
</View>
)}
</View>
);
}- The Google Places API must be enabled on your Google Cloud Platform account
- A request quota applies according to your Google pricing plan
- The component supports English and other languages via the language parameter in requests
- Filtered places exclude certain types (routes, intersections, etc.) to improve user experience
- The component automatically cancels ongoing requests on unmount or new search
MIT
Made with MJdiop