
Product
Rust Support Now in Beta
Socket's Rust support is moving to Beta: all users can scan Cargo projects and generate SBOMs, including Cargo.toml-only crates, with Rust-aware supply chain checks.
rn-use-google-places-autocomplete
Advanced tools
An easy-to-use hook for integrating Google Places Autocomplete in your app with Maps API. ๐
A fully-typed and modern React Native hook for consuming Google Places API v1, without axios
or unnecessary dependencies.
The goal was to build a lightweight, developer-friendly and React Native-compliant hook that allows you to easily integrate Google Places Autocomplete in your apps, with geolocation support โ all typed, simple, and production-ready.
Most existing packages either:
axios
, which bloats your bundleThis solves all that in one clean, open-source package ๐
npm install rn-use-google-places-autocomplete
# or
yarn add rn-use-google-places-autocomplete
Before you start using this package, ensure that youโve properly set up your Google Cloud Platform (GCP) project and API keys. Here are the steps to follow:
Note: Google Cloud offers a free tier, and you wonโt be charged unless your usage exceeds the free tier limits.
In order to use Google Places Autocomplete and Geocoding, you must enable the following APIs:
For a complete guide on setting up your API keys, see Googleโs official documentation.
import useGooglePlacesAutocomplete from "use-google-places-autocomplete";
import { useGooglePlacesAutocomplete } from 'rn-use-google-places-autocomplete';
import { Text, View, TextInput, FlatList, TouchableOpacity, RefreshControl, } from 'react-native';
export default function App() {
const { query, setQuery, places, loading, error } =
useGooglePlacesAutocomplete({
gcpApiKey: "YOUR_GOOGLE_API_KEY",
language: "en", // or "fr", etc.
countries: ["FR", "US"], // Optional country filter
});
return(
<View>
// Bind `query` to your input and render `places`
<TextInput
placeholder="Search a place..."
value={query}
onChangeText={setQuery}
/>
// Render the places
<FlatList
refreshControl={
<RefreshControl
onRefresh={() => {}}
refreshing={loading}
/>
}
refreshing={loading}
data={places}
keyExtractor={(item) => item.id}
renderItem={({ item }) => (
<TouchableOpacity onPress={() => {}}>
<Text>{item.name}</Text>
<Text>{item.fullAddress}</Text>
<Text>
Lat : {item.latitude} | Long : {item.longitude}
</Text>
</TouchableOpacity>
)}
/>
</View>
)
}
useGooglePlacesAutocomplete(props)
Prop | Type | Required | Description |
---|---|---|---|
gcpApiKey | string | โ | Your Google Cloud API Key with Places and Geocoding enabled |
language | string | โ | Language code (default is 'fr' ) |
countries | string[] | โ | Country restriction (e.g., ['FR', 'US'] ) |
autocompUrl | string | โ | Override autocomplete endpoint |
geocodingUrl | string | โ | Override geocoding endpoint |
timeoutValue | number | โ | Override timeout (default is 1500) |
Field | Type | Description |
---|---|---|
query | string | The current user input |
setQuery | function | Update the query string |
places | Place[] | List of place suggestions with metadata |
loading | boolean | Whether a request is in progress |
error | string | null | Any API or fetch error |
Place
Object Structureinterface Place {
id: string;
name: string;
fullAddress: string;
types: string[];
latitude: number | null;
longitude: number | null;
address_components: {
mainText: { text: string };
secondaryText: { text: string };
};
raw?: PlacePrediction; // Full Google prediction object
}
You can view the demo video by clicking here.
PRs are welcome! If youโd like to add features (like place detail fetch), feel free to open an issue or contribute directly.
I build production-grade mobile experiences, MVPs and complex app architectures.
๐ง Contact me at contact@devops-office.com
MIT โ Free for personal and commercial use.
FAQs
An easy-to-use hook for integrating Google Places Autocomplete in your app with Maps API. ๐
We found that rn-use-google-places-autocomplete demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago.ย It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket's Rust support is moving to Beta: all users can scan Cargo projects and generate SBOMs, including Cargo.toml-only crates, with Rust-aware supply chain checks.
Product
Socket Fix 2.0 brings targeted CVE remediation, smarter upgrade planning, and broader ecosystem support to help developers get to zero alerts.
Security News
Socket CEO Feross Aboukhadijeh joins Risky Business Weekly to unpack recent npm phishing attacks, their limited impact, and the risks if attackers get smarter.