npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

Iโ€™ve always been into building performant and accessible sites, but lately Iโ€™ve been taking it extremely seriously. So much so that Iโ€™ve been building a tool to help me optimize and monitor the sites that I build to make sure that Iโ€™m making an attempt to offer the best experience to those who visit them. If youโ€™re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, ๐Ÿ‘‹, Iโ€™m Ryan Hefnerย  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If youโ€™re interested in other things Iโ€™m working on, follow me on Twitter or check out the open source projects Iโ€™ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soonโ€“ish.

Open Software & Tools

This site wouldnโ€™t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you ๐Ÿ™

ยฉ 2026 โ€“ย Pkg Stats / Ryan Hefner

rn-use-google-places-autocomplete

v1.1.1

Published

An easy-to-use hook for integrating Google Places Autocomplete in your app with Maps API. ๐Ÿš€

Downloads

370

Readme

๐Ÿ—บ๏ธ useGooglePlacesAutocomplete

A fully-typed and modern React Native hook for consuming Google Places API v1, without axios or unnecessary dependencies.

โœจ Why this package?

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:

  • Use outdated APIs (Place Autocomplete v1 is recommended)
  • Rely on axios, which bloats your bundle
  • Arenโ€™t tailored for React Native
  • Lack proper TypeScript support

This solves all that in one clean, open-source package ๐Ÿš€


๐Ÿ“ฆ Installation

npm install rn-use-google-places-autocomplete
# or
yarn add rn-use-google-places-autocomplete

๐Ÿ› ๏ธ Setup Before Use

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:

1. Create a Google Cloud Project

  1. Access the Google Cloud Console: Go to Google Cloud Console.
  2. Create a New Project: Click on the project dropdown and select "New Project". Give it a name and create it.

2. Enable Billing

  1. Enable Billing for Your Project: You need to link a billing account to your project. If you donโ€™t have one, create it following the instructions in the console.

Note: Google Cloud offers a free tier, and you wonโ€™t be charged unless your usage exceeds the free tier limits.

3. Enable Required APIs

In order to use Google Places Autocomplete and Geocoding, you must enable the following APIs:

  • Places API
  • Geocoding API

a. Enable APIs:

  1. Go to the API Library in the Google Cloud Console.
  2. Enable Places API:
    • Search for "Places API", select it, and click "Enable".
  3. Enable Geocoding API:
    • Search for "Geocoding API", select it, and click "Enable".

4. Create an API Key

  1. Navigate to API Credentials: In the Google Cloud Console, go to "APIs & Services" > "Credentials".
  2. Create a New API Key:
    • Click on "Create Credentials" and choose "API Key".
    • Copy the generated key. This key will be used in your app.
  3. Restrict Your API Key (Recommended):
    • To prevent unauthorized usage, restrict the key to only work with your allowed referrers (such as your domain or mobile app).
    • You can also restrict the key to only the Places and Geocoding APIs.

For a complete guide on setting up your API keys, see Googleโ€™s official documentation.


๐Ÿ› ๏ธ Usage

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>
  )
}

๐Ÿง  Features

  • โœ… Fully typed (TypeScript ready)
  • โœ… Google Places API v1 compatible
  • โœ… Geocoding (lat/lng) included
  • โœ… Customizable endpoints (for advanced use)
  • โœ… Designed for React Native
  • โœ… No external dependencies

๐Ÿ“„ API

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) |

Returns

| 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 Structure

interface 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
}

๐Ÿš€ Demo

๐Ÿ“บ Demo Video

You can view the demo video by clicking here.


๐Ÿค Contribute

PRs are welcome! If youโ€™d like to add features (like place detail fetch), feel free to open an issue or contribute directly.


๐Ÿ’ฌ Need a custom React Native component?

I build production-grade mobile experiences, MVPs and complex app architectures.
๐Ÿ“ง Contact me at [email protected]


๐Ÿ“„ License

MIT โ€“ Free for personal and commercial use.