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

google-place-provider

v1.3.4

Published

google place search api service provider

Downloads

330

Readme

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 {
    predictions: Prediction[];
    status: Status;
}

export interface PlaceDetailHTTPResult {
    html_attributions: string[];
    result: PlaceDetailResult;
    status: Status;
}

export interface Prediction {
    description: string;
    id: string;
    matched_substrings: MatchedSubstring[];
    place_id: string;
    reference: string;
    structured_formatting: {
        main_text: string;
        main_text_matched_substrings: MatchedSubstring[];
        secondary_text: string;
    };
    terms: OffsetValue[];
    types: string[];
}

export interface MatchedSubstring {
    length: number;
    offset: number;
}

export interface OffsetValue {
    offset: number;
    value: string;
}

export interface PlaceDetailResult {
    address_components: LongNameShortName[];
    adr_address: string;
    formatted_address: string;
    formatted_phone_number: string;
    geometry: Geometry;
    icon: string;
    id: string;
    international_phone_number: string;
    name: string;
    place_id: string;
    rating: number;
    reference: string;
    reviews: Review[];
    types: string[];
    url: string;
    utc_offset: number;
    vicinity: string;
    website: string;
}

export interface LongNameShortName {
    long_name: string;
    short_name: string;
    types: string[];
}

export interface Geometry {
    location: Location;
    viewport: {
        northeast: Location;
        southwest: Location;
    };
}

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

export interface Review {
    author_name: string;
    author_url: string;
    language: string;
    profile_photo_url: string;
    rating: number;
    relative_time_description: string;
    text: string;
    time: number;
}

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