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-maps-api-stream

v1.1.0

Published

Streaming, rate-limited interface to Google Maps API Web Services

Downloads

2

Readme

google-maps-api-stream Build Status

A streaming, rate-limited, and caching interface to Google Maps APIs

npm install google-maps-api-stream --save

Usage

ES6 Syntax

import {Geocoding} from 'google-maps-api-stream';

const geocoder = new Geocoding({
  googleMaps: {
    key: 'your-api-key'
  },
  cacheFile: 'geocache.db'
});

geocoder.on('data', data => console.log(data));
geocoder.on('end', () => console.log('Done.'));

geocoder.write('Hamburg, Germany');
geocoder.write('Las Vegas');
geocoder.end();

ES5 Syntax

var mapsApi = require('google-maps-api-stream');
var Geocoding = mapsApi.Geocoding;

var geocoder = new Geocoding({
  googleMaps: {
    key: 'your-api-key'
  },
  cacheFile: 'geocache.db'
});

geocoder.on('data', data => console.log(data));
geocoder.on('end', () => console.log('Done.'));

geocoder.write('Hamburg, Germany');
geocoder.write('Las Vegas');
geocoder.end();

Further examples can be found in examples/

Response Format

All interfaces share the following response format:

{
  input: '', // input data, before the accessor was applied
  query: '', // input data, after the accessor was applied
  stats: {current: 1},
  response: ... // response format depends on the interface
  error: false,
  cached: false
}

API Documentation

All interfaces are NodeJS transform streams. Input data can be passed in by writing or piping to them. They emit the data, and end events. All interfaces accept an options object upon initialisation. The following options may be set:

options.googleMaps: Type: <Object>, default: {}. Options passed to the googlemaps module. You must set either a key property, containing a Google Maps API key, or a clientId and privateKey. Consult the googlemaps package documentation for other options.

options.queriesPerSecond: Type: <Number>, default: 35. Maximum number of queries per second.

options.cacheFile: Type: <String>, default: null. Path to a file for caching queries. A cache will not be used if this path is set to null.

options.accessor: Type: <Function>, default: function(data) { return data; }. This function can be used to transform data written to the stream before it is passed to the API.

options.stats: Type: <Object>, default: {current: 0}. A stats object which will be attached to every result. The value of stats.current is incremented with every query.

The Google Maps API stream module currently provides streaming interfaces to the following Google Maps APIs:

Directions

var directionsInterface = new mapsApi.Directions(options);

Required query parameters:

const query = {
  origin: 'address || lat,lng',
  destination: 'address || lat,lng'
};

Refer to Request Parameters for optional parameters.

Response format:
Google Directions Response

Geocoding

var geocoder = new mapsApi.Geocoding(options);

Required query parameters:

const query = {
  address: 'Some address, Sometown, Earth'
};

or

const query = 'Some address, Sometown, Earth';

Refer to Request Parameters for optional parameters.

Response format:
Google Geocoding Response

Reverse Geocoding

const query = {
  latlng: '53.5610771,9.9569145'
};

or

const query = {
  place_id: 'ChIJa76xwh5ymkcRW-WRjmtd6HU'
};

Refer to Request Parameters for optional parameters.

Response format:
Google Reverse Geocoding Response

Static Maps Images

Required query parameters:

const query = {
  center: 'lat,lng',
  zoom: number
  size: '{width}x{height}'
};

Refer to URL Parameters for optional parameters.

Response format:
A binary blob containing the static maps image

Static Maps URLs

Required query parameters:

const query = {
  center: 'lat,lng',
  zoom: number
  size: '{width}x{height}'
};

Refer to URL Parameters for optional parameters.

Response format:
A string containing the URL to the static maps image

Street View Images

Required query parameters:

const query = {
  location: '51.507868,-0.087689',
  size: '1200x1600'
};

or

const query = {
  pano: '<pano id>',
  size: '1200x1600'
};

Refer to URL Parameters for optional parameters.

Response format:
A binary blob containing the static maps image