Home

@google/maps 0.5.5

Welcome to the reference docs for the Node.js Client for Google Maps Services.

Quick Start

Create a new client object by calling createClient():

var googleMapsClient = require('@google/maps').createClient({
  key: 'your API key here'
});

Make requests to the Google Maps APIs by calling methods on the client object:

// Geocode an address.
googleMapsClient.geocode({
  address: '1600 Amphitheatre Parkway, Mountain View, CA'
}, function(err, response) {
  if (!err) {
    console.log(response.json.results);
  }
});

Initializing the client library

You can specify a number of options to the createClient() function:

  • Specify an API key or a client ID (required)
  • Customize the rate limit on requests (default limit is 10 requests per second)
  • Specify a Promise constructor, so that you can receive responses via the Promise API. This leaves you free to choose your Promise implementation.

Making API requests

Each API method accepts two arguments:

  • a query object; and
  • a callback function. The callback is called with either the JSON response object or an error object.

Each API method returns a RequestHandle. The handle can be used to cancel the request, or to obtain a Promise for the response.

NOTE: Promises are only available if you supply a Promise constructor to the createClient() method. You must also chain .asPromise() to a method before any .then() or .catch() methods. For example:

// Create client with a Promise constructor
const googleMapsClient = require('@google/maps').createClient({
  key: 'your API key here',
  Promise: Promise // 'Promise' is the native constructor.
});

// Geocode an address with a promise
googleMapsClient.geocode({address: '1600 Amphitheatre Parkway, Mountain View, CA'}).asPromise()
  .then((response) => {
    console.log(response.json.results);
  })
  .catch((err) => {
    console.log(err);
  });

Learn More