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 🙏

© 2024 – Pkg Stats / Ryan Hefner

expo-google-places-autocomplete

v1.2.0

Published

Google Places Autocomplete for React Native

Downloads

972

Readme

expo-google-places-autocomplete

Google Places Autocomplete for React Native. This library uses the native Google Places SDK for iOS and Android.

Preview

Installation

npx expo install expo-google-places-autocomplete

For bare React Native projects, you must ensure that you have installed and configured the expo package before continuing.

Configuration for iOS 🍏

This is only required for usage in bare React Native apps.

Run npx pod-install after installing the npm package.

Configuration for Android 🤖

No further steps are needed on Android

Get your api key

Create a an API key here and enable the "Places API". You must have billing enabled on the account.

Usage

import { GooglePlacesAutocomplete } from "expo-google-places-autocomplete";

// ...
const onSearchError = React.useCallback((error: PlacesError) => {
  console.log(error);
}, []);

const onPlaceSelected = React.useCallback((place: PlaceDetails) => {
  console.log(place);
}, []);

<View>
  <GooglePlacesAutocomplete
    apiKey={API_KEY}
    requestConfig={{ countries: ["US"] }}
    onPlaceSelected={onPlaceSelected}
    onSearchError={onSearchError}
  />
</View>;

Build your own

The library exposes three fucntions that you can use to build your own autocomplete component.

Start by initializing the SDK with your API key.

import PlacesAutocomplete from "expo-google-places-autocomplete";

// ...

useEffect(() => {
  PlacesAutocomplete.initPlaces(apiKey);
}, [apiKey]);

To get a list of predictions based on a users input you can attach an onChangeText handler to your TextInput and pass in your RequestConfig object. You will be returned an array of Place objects with at most 6 results.

  // ...
  const [inputValue, setInputValue] = React.useState("");
  const [results, setResults] = React.useState<Place[]>([]);

  // ...
  const onChangeText = React.useCallback(
    async (text: string) => {
      try {
        let result = await PlacesAutocomplete.findPlaces(text, requestConfig);
        setResults(result.places);
        setInputValue(text);
      } catch (e) {
        console.log(e);
      }
    },
    [requestConfig],
  );

When an item is selected from your list of results you can get the PlaceDetails with the following

const onPlaceSelected = React.useCallback(
  async (placeId: string) => {
    try {
      const details = await PlacesAutocomplete.placeDetails(placeId);
      console.log(details);
    } catch (e) {
      console.log(e);
    }
  },
  [onPlaceSelected],
);

Styling the provided component

| key | type | | --------------------- | --------- | | containerStyle | ViewStyle | | searchInputStyle | ViewStyle | | inputContainerStyle | ViewStyle | | resultsContainerStyle | ViewStyle | | resultItemStyle | ViewStyle | | listFooterStyle | ViewStyle |

Contributing

Contributions are welcome!