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

react-native-google-places-search

v1.0.0

Published

Google Places SDK for React Native

Downloads

3

Readme

Google Places SDK for React Native

Google Places SDK for React Native. Places SDK allows you to build location aware apps that responds contextutally to the local businesses and other places near the user's device.

CI Licence

Table of contents

Requirements

Minimum Platform Version

  • Android: 21
  • iOS: 13

Google Places API Key

Installation

npm install react-native-google-places-search
#OR
yarn add react-native-google-places-search

Usage

Initialize SDK

initialize(apiKey: string): void

SDK needs to be initialize only once per App start before using any other functions. Preferably in the root file, e.g., App.tsx.

import GooglePlacesSDK from 'react-native-google-places-search';

const GOOGLE_PLACES_API_KEY = ""; // add your Places API key
GooglePlacesSDK.initialize(GOOGLE_PLACES_API_KEY);

Fetch Predictions

fetchPredictions(query: string, filters?: PredictionFiltersParam): Promise<PlacePrediction[]>

PredictionFiltersParams

type PredictionFiltersParam = {
  types?: string[];
  countries?: string[];
  locationBias?: LocationBounds;
  locationRestriction?: LocationBounds;
  origin?: LatLng;
};

PlacePrediction

type PlacePrediction = {
  description: string;
  placeID: string;
  primaryText: string;
  secondaryText: string;
  types: string[];
  distanceMeters: number;
}

Sample Output

{
  "description": "Mumbai, Maharashtra, India",
  "distanceMeters": null,
  "placeID": "ChIJwe1EZjDG5zsRaYxkjY_tpF0",
  "primaryText": "Mumbai",
  "secondaryText": "Maharashtra, India",
  "types": [
    "locality",
    "political",
    "geocode"
  ]
}

Sample Implementation

import GooglePlacesSDK, { PLACE_FIELDS } from 'react-native-google-places-search';

GooglePlacesSDK.fetchPredictions(
  query = "Mumbai",
  filters = { countries: ["in", "us"] }
)
  .then((predictions) => console.log(predictions));
  .catch((error) => console.log(error));

// ...

Fetch Place By ID

fetchPlaceByID(placeID: string, fields?: FieldsParam): Promise<Place>

FieldsParam

  • Allowed Fields: Refer PLACE_FIELDS in 'react-native-google-sdk'

  • If no fields or empty array is passed, then all fields will be fetched for given the place ID.

// type
string[]

// Example
import { PLACE_FIELDS } from 'react-native-google-places-search';

const fields = [PLACE_FIELDS.NAME, PLACE_FIELDS.PLACE_ID, PLACE_FIELDS.ADDRESS_COMPONENTS]

Place

type Place = {
  name: string | null;
  placeID: string | null;
  plusCode: string | null;
  coordinate: LatLng | null;
  openingHours: string | null;
  phoneNumber: string | null;
  types: string[] | null;
  priceLevel: number | null;
  website: string | null;
  viewport: (LocationBounds & { valid: boolean }) | null;
  formattedAddress: string | null;
  addressComponents:
    | {
        types: string[];
        name: string;
        shortName: string;
      }[]
    | null;
  attributions: string | null;
  rating: number;
  userRatingsTotal: number;
  utcOffsetMinutes: number | null;
  iconImageURL: string | null;
  businessStatus: BusinessStatus;
  dineIn: AtmosphereCategoryStatus;
  takeout: AtmosphereCategoryStatus;
  delivery: AtmosphereCategoryStatus;
  curbsidePickup: AtmosphereCategoryStatus;
  photos: {
    attributions: {
      url: string;
      name: string;
    };
    reference: string;
    width: number;
    height: number;
  }[];
};

Sample Implementation

import GooglePlacesSDK, { PLACE_FIELDS } from 'react-native-google-places-search';

GooglePlacesSDK.fetchPlaceByID(
  placeID = "ChIJwe1EZjDG5zsRaYxkjY_tpF0",
  fields = [PLACE_FIELDS.NAME, PLACE_FIELDS.TYPES]
)
  .then((place) => console.log(place));
  .catch((error) => console.log(error));
// ...

Special Thanks

This is a clone of React-Native-Google-Places-SDK package.

Contributing

See the contributing guide to learn how to contribute to the repository and the development workflow.

License

MIT