
Security News
ECMAScript 2025 Finalized with Iterator Helpers, Set Methods, RegExp.escape, and More
ECMAScript 2025 introduces Iterator Helpers, Set methods, JSON modules, and more in its latest spec update approved by Ecma in June 2025.
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. π
The npm package rn-use-google-places-autocomplete receives a total of 26 weekly downloads. As such, rn-use-google-places-autocomplete popularity was classified as not popular.
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.
Security News
ECMAScript 2025 introduces Iterator Helpers, Set methods, JSON modules, and more in its latest spec update approved by Ecma in June 2025.
Security News
A new Node.js homepage button linking to paid support for EOL versions has sparked a heated discussion among contributors and the wider community.
Research
North Korean threat actors linked to the Contagious Interview campaign return with 35 new malicious npm packages using a stealthy multi-stage malware loader.