Socket
Socket
Sign inDemoInstall

google-places-web

Package Overview
Dependencies
3
Maintainers
1
Versions
24
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    google-places-web

A simple wrapper for the Google Places Web API


Version published
Maintainers
1
Created

Readme

Source

Google Places Web

A promise-based wrapper for the Google Places JS SDK for Node (and React Native).

Installation

yarn add google-places-web;
npm i google-places-web -S

Importing

// ES6
import Places from "google-places-web";

// ES5
const Places = require("google-places-web").default; // instance of GooglePlaces Class;

// Setup
Places.apiKey = "<API_KEY>";
Places.debug = __DEV__; // boolean;

Places Autocomplete

let partialAddress = "1600 Pennsylv";
const radius = 2000;
const language = "en";

// Search with default opts
Places.autocomplete({ input: partialAddress, radius, language })
  .then(results => {
    // results array of partial matches
  })
  .catch(e => console.log(e));

Places Details

const whiteHousePlaceID = "ChIJGVtI4by3t4kRr51d_Qm_x58";

Places.details({ placeid: whiteHousePlaceID })
  .then(result => {
    // result object
  })
  .catch(e => console.log(e));

Full Example

Make sure you have the lib built with npm run build or yarn build. That should create your dist/ directory.

> npm run build

> PLACES_API_KEY=<your_key_here> node examples/places-example.js

Troubleshooting

Feel free to file issues as you see fit, and always looking for collaborators to help make this better.

Errors

  • Invalid API Key - The instance of the GooglePlaces object does not have a valid API key from Google. Make sure you are either using import Places from... or import {GooglePlaces} from.... GooglePlaces is the base class so you would need to make an instance of it first.
  • STATUS_MESSAGE - Google responds with HTTP 200 but JSON contains an "error". This is parsed from the Google API response, ex. ZERO_RESULTS
  • Missing required params: [<PARAM1>, <PARAM2>] - Required params PARAM1 & PARAM2 are undefined or null
  • No parameters provided - A method was called without passing a parameters object to the method, most likely passed null, undefined or nothing. ex. Places.autocomplete(); instead of Places.autcomplete({foo: 'barr});

Important Notes

Google states that you can use Place Autocomplete even without a map. If you do show a map, it must be a Google map. When you display predictions from the Place Autocomplete service without a map, you must include the Powered by Google logo.

Keywords

FAQs

Last updated on 10 Sep 2018

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc