1.8.0 • Published 1 year ago

@gojob/google-place v1.8.0

Weekly downloads
25
License
MIT
Repository
github
Last release
1 year ago

@gojob/google-place

travis build Coverage Status

Description

This package is a library for Node.js to consume the Google Place autocomplete & details API. It returns a small subset of their data.

Installation

yarn add @gojob/google-place

Usage

import * as gp from '@gojob/google-place';

Autocomplete API

const results = await gp.autocomplete({
    key: 'YOUR_API_KEY',
    input: 'Port-de-Bouc',
    language: 'fr',
    countries: ['fr'],
});

gp.autocomplete(query)

NameTypeDescription
keystringGoogle API Key
inputstringSearched entry
languagestringLanguage to use (optional) Google Code
countriesstring[]Filter on a country (optional) ISO 3166-1 Alpha-2

Returns a list of prediction or throw if an error occurred.

interface IPrediction {
  id: string;
  name: string;
}

As:

NameTypeDescription
idstringPlace id
namestringPlace name

gp.retrieve(query)

const place = gp.retrieve({
    key: 'YOUR_API_KEY',
    id: 'ChIJ-RzUxt8ethIRksIaOl-0tJY',
    language: 'fr',
});

As:

NameTypeDescription
keystringGoogle API Key
idstringSearched entry
languagestringLanguage to use (optional) Google Code

Returns a place or throw if an error occurred.

export interface ILocation {
  lat: number;
  lng: number;
}

export interface IPlace {
  id: string;
  address: string;
  location: ILocation;
  postalCode: string;
  locality: string;
  administrativeAreaLevel1: string;
  administrativeAreaLevel2: string;
  countryCode: string;
  country: string;
}

As:

NameTypeDescription
idstringPlace id
addressstringFormatted address
locationobjectLatitude and longitude coordinates
postalCodestringPostal code
localitystringLocality name (long or short name)
administrativeAreaLevel1stringAdministrative Area Level 1 (long or short name)
administrativeAreaLevel2stringAdministrative Area Level 2 (long or short name)
countryCodestringCountry short name
stateCodestringAdministrative Area Level 1 (short name)
countrystringCountry name (long name)

postalCode, administrativeAreaLevel1 or administrativeAreaLevel2 may be empty string

gp.reverseGeocode(opts)

const place = gp.reverseGeocode({
    key: 'YOUR_API_KEY',
    latlng: 'XXX,YYY',
    language: 'fr',
});

As:

NameTypeDescription
keystringGoogle API Key
latlngstringLatitude and longitude coordinates (coma separated)
languagestringLanguage to use (optional) Google Code

Find an address from a location coordinates. Returns a IPlace.

1.8.0

1 year ago

1.7.0

2 years ago

1.6.3

5 years ago

1.6.2

5 years ago

1.6.1

5 years ago

1.6.0

5 years ago

1.5.0

5 years ago

1.4.0

6 years ago

1.2.0

6 years ago

1.1.0

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago