google-place-provider
TypeScript icon, indicating that this package has built-in type declarations

1.3.4 • Public • Published

google-place-provider

This package provides google place API (with very simplified options)

We provide

  1. autocomplete
  2. place details
  3. find place search
  4. nearby search
  5. place photo
  6. text search

see original documents of google place

  1. google place autocomplete
  2. google place place details
  3. google place find place search
  4. google place nearby search
  5. google place photo
  6. google place text search

how to use

$ yarn add google-place-provider
import GooglePlaceProvider from 'google-place-provider';
 
async function main() {
    try {
        // create googlePlace class object
        const googlePlace = new GooglePlaceProvider('YOUR_API_KEY');
 
        // autocomplete
        const autocomplete = await googlePlace.autocomplete('hello');
        console.log(autocomplete);
 
        // placeDetails
        const placeDetails = await googlePlace.placeDetails(
            'ChIJN1t_tDeuEmsRUsoyG83frY4'
        );
        console.log(placeDetails);
 
        // findPlaceSearch
        const findPlaceSearch = await googlePlace.findPlaceSearch({
            input: 'Museum of Contemporary Art Australia',
            inputtype: PlaceSearchInputTypes.TEXT_QUERY,
            fields:
                'photos,formatted_address,name,rating,opening_hours,geometry',
        });
        console.log(findPlaceSearch);
 
        // nearbySearch
        const nearbySearch = await googlePlace.nearbySearch({
            language: 'en',
            radius: 1500,
            location: '-33.8670522,151.1957362',
            type: 'restaurant',
            keyword: 'cruise',
        });
        console.log(nearbySearch);
 
        // placePhoto
        const placePhoto = await googlePlace.placePhoto({
            maxwidth: 400,
            photoreference:
                'CnRtAAAATLZNl354RwP_9UKbQ_5Psy40texXePv4oAlgP4qNEkdIrkyse7rPXYGd9D_Uj1rVsQdWT4oRz4QrYAJNpFX7rzqqMlZw2h2E2y5IKMUZ7ouD_SlcHxYq1yL4KbKUv3qtWgTK0A6QbGh87GB3sscrHRIQiG2RrmU_jF4tENr9wGS_YxoUSSDrYjWmrNfeEHSGSc3FyhNLlBU',
        });
        console.log(placePhoto);
 
        // textSearch
        const textSearch = await googlePlace.textSearch({
            query: '123 main street',
        });
        console.log(textSearch);
    } catch (e) {
        throw e;
    }
}
 
main();

types

import { AutocompleteHTTPResult, PlaceDetailHTTPResult, Prediction, ... } from 'google-place-provider';

type list

you can check more of types in type.ts

export interface AutocompleteHTTPResult {
    predictionsPrediction[];
    statusStatus;
}
 
export interface PlaceDetailHTTPResult {
    html_attributionsstring[];
    resultPlaceDetailResult;
    statusStatus;
}
 
export interface Prediction {
    descriptionstring;
    idstring;
    matched_substringsMatchedSubstring[];
    place_idstring;
    referencestring;
    structured_formatting: {
        main_textstring;
        main_text_matched_substringsMatchedSubstring[];
        secondary_textstring;
    };
    terms: OffsetValue[];
    types: string[];
}
 
export interface MatchedSubstring {
    lengthnumber;
    offsetnumber;
}
 
export interface OffsetValue {
    offsetnumber;
    valuestring;
}
 
export interface PlaceDetailResult {
    address_componentsLongNameShortName[];
    adr_addressstring;
    formatted_addressstring;
    formatted_phone_numberstring;
    geometryGeometry;
    iconstring;
    idstring;
    international_phone_numberstring;
    namestring;
    place_idstring;
    ratingnumber;
    referencestring;
    reviewsReview[];
    typesstring[];
    urlstring;
    utc_offsetnumber;
    vicinitystring;
    websitestring;
}
 
export interface LongNameShortName {
    long_namestring;
    short_namestring;
    typesstring[];
}
 
export interface Geometry {
    locationLocation;
    viewport: {
        northeastLocation;
        southwestLocation;
    };
}
 
export interface Location {
    latnumber;
    lngnumber;
}
 
export interface Review {
    author_namestring;
    author_urlstring;
    languagestring;
    profile_photo_urlstring;
    ratingnumber;
    relative_time_descriptionstring;
    textstring;
    timenumber;
}
 
enum Status {
    OK = 'OK',
    ZERO_RESULTS = 'ZERO_RESULTS',
    OVER_QUERY_LIMIT = 'OVER_QUERY_LIMIT',
    REQUEST_DENIED = 'REQUEST_DENIED',
    INVALID_REQUEST = 'INVALID_REQUEST',
    UNKNOWN_ERROR = 'UNKNOWN_ERROR',
}
 

how to test

  1. create .env file on same level of folder of src/
  2. like .env.copy, add GOOGLE_API_KEY value on .env
  3. follow bottoms
$ yarn test

Package Sidebar

Install

npm i google-place-provider

Weekly Downloads

106

Version

1.3.4

License

MIT

Unpacked Size

47.1 kB

Total Files

29

Last publish

Collaborators

  • yungblud