Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@google/maps

googlemaps224.7kApache-2.0deprecated1.1.3TypeScript support: definitely-typed

Please use @googlemaps/google-maps-services-js instead.

Node.js client library for Google Maps API Web Services

google, maps, googlemaps, geo, geocode, timezone, api, client, roads, directions, navigation

readme

Node.js Client for Google Maps Services

Build Status npm codecov GitHub contributors

This library has been deprecated in favor of @googlemaps/google-maps-services-js. Bug fixes will continue, however all new feature development will be on the master branch and published to the new library.

Use Node.js? Want to geocode something? Looking for directions? This library brings the Google Maps API Web Services to your Node.js application. Analytics

The Node.js Client for Google Maps Services is a Node.js Client library for the following Google Maps APIs:

Keep in mind that the same terms and conditions apply to usage of the APIs when they're accessed through this library.

Attention!

This library is designed for server-side Node.js applications. Attempting to use it client-side, in either the browser or any other environment like React Native, may in some cases work, but mostly will not. Please refrain from reporting issues with these environments when attempting to use them, since server-side Node.js applications is the only supported environment for this library. For other environments, try the Maps JavaScript API, which contains a comparable feature set, and is explicitly intended for use with client-side JavaScript.

Features

  • Retry on Failure Automatically retry when intermittent failures occur. That is, when any of the retryable 5xx errors are returned from the API.

  • Rate-limiting Requests are rate-limited by the client, which helps prevent reaching the server-enforced rate limit.

Quick Start

$ npm install @google/maps

Note: You'll need to have npm 2.7.0 or greater installed, since this library is hosted as a scoped package.

Create a new client object by calling createClient()

const 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);
  }
});

You may use promise-based solution also.

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

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

For more usage examples, check out the tests.

View the reference documentation

Additional documentation for the included web services is available at https://developers.google.com/maps/.

API keys

Each Google Maps Web Service request requires an API key. To get an API key, follow the Get API Key instructions in our Maps JS API docs.

When you have an API key, you can create a client object:

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

Client IDs

Google Maps APIs Premium Plan customers can use their client ID and secret to authenticate, instead of an API key.

var googleMapsClient = require('@google/maps').createClient({
  clientId: 'Add your client ID here',
  clientSecret: 'Add your client secret here',
});

Important: This key should be kept secret on your server.

Typescript

Community-built typings for this library are available in @types/google__maps (note the double underscore).

npm install @types/google__maps

Developing

In order to run the end-to-end tests, you'll need to supply your API key via an environment variable.

$ export GOOGLE_MAPS_API_KEY=AIza-your-api-key
$ npm test

Support

This library is community supported. We're comfortable enough with the stability and features of the library that we want you to build real production applications on it. We will try to support, through Stack Overflow, the public surface of the library and maintain backwards compatibility in the future; however, while the library is in version 0.x, we reserve the right to make backwards-incompatible changes. If we do remove some functionality (typically because better functionality exists or if the feature proved infeasible), our intention is to deprecate and give developers a year to update their code.

If you find a bug, or have a feature suggestion, please log an issue. If you'd like to contribute, please read How to Contribute.

Command-line Interface

Installing via npm also provides the googlemaps command-line utility, which can then be used to pipe JSON results to other command-line programs:

$ googlemaps directions --origin 'Sydney Town Hall' --destination 'Parramatta, NSW'

changelog

Changelog

All notable changes to this project will be documented in this file.

Unreleased

1.1.0 - 2020-01-21

Changed

  • added support for experience id header in #304
  • simplified e2e tests in #305

1.0.2 - 2019-10-21

Changed

  • updated dependencies in #294

1.0.1 - 2019-09-20

Changed

1.0.0 - 2019-09-11

Merged

  • add support for subfields in mask #269
  • remove deprecated places radar #271
  • run e2e tests separately #272
  • add contributor and stackoverflow badges #273
  • add github issue templates #268
  • updates package-lock.json #266
  • adds code coverage reporting #265
  • updates deps to fix npm audit reported vulnerability #263
  • fixed reviews field name #255
  • Adds plus_code to findPlace field and fixes some tests #256
  • Check content-type without significance of case-sensitivity #249
  • distance matrix departure time unit change from miliseconds to seconds #124
  • fixes #196 #247
  • Add the "origin" parameter to the placesAutoComplete function #245
  • docs: Add npm badge #242
  • fixes pagination INVALID_REQUEST handling #230
  • added https proxy agent for pursuing the requests behind corporate proxy #226
  • Session token should be optional in AutoComplete #221
  • Test against modern node versions #201
  • Consistently use const in README #202
  • Pull request to allow multiple components of each type #192
  • placesPhoto should throw error if neither maxwidth or maxheigh is declared #190

Fixed

  • fixes #196 (#247) #196

Commits

  • Upgrades Jasmine dep e06b1e2
  • rewrote unit tests, moved to unit/convert-spec 73e7d20
  • Comments out tests for speed limit since the feature isn't widely available a6bfa97

0.5.5 - 2018-07-17

Fixed

  • Fix locationbias validation. Closes #182 #182

Commits

0.5.4 - 2018-07-09

Commits

  • Don't use regex for locationbias validation 27fff4e
  • Version 0.5.4 0e158a6

0.5.3 - 2018-07-02

Commits

0.5.2 - 2018-07-02

Commits

0.5.1 - 2018-07-02

Commits

  • Version 0.5.1 507682e
  • Add sessiontoken param to place details 1308376

0.5.0 - 2018-06-25

Merged

  • Add findplacebytext method and fields params #170
  • Catch JSON.parse errors. #140
  • Update docs #157

Fixed

  • Fix broken docs links. Closes #174. #174
  • Add polyline encode/decode utils. Closes #162. #162

Commits

  • Better format for jsdoc 6800f7f
  • location param for places nearby is not required if pagetoken provided d5efe51
  • Add locationbias field to findplacefromtext bab91d7

0.4.6 - 2018-03-18

Merged

  • Add region parameter to Text Search API #131
  • Update directions-spec.js #133
  • Fixing errors in Github-flavored markdown #127

Commits

  • Better CLI error handling. de079e7
  • Catch JSON.parse errors. 550d1e8
  • Increase default QPS from 10 to 50 22e98d4

0.4.5 - 2017-10-12

Commits

0.4.4 - 2017-10-11

Merged

  • Fix JSDoc for geocode bounds parameter #113

Fixed

  • Fix default arg handling. Closes #123. #123

Commits

  • Clarify speedLimits vs snappedSpeedLimits 2561db7
  • Version 0.4.4 17ac1e5

0.4.3 - 2017-07-25

Merged

  • Added example of promise constructor #103

Fixed

  • Fix response handling for successful non-json responses, namely places photo. Closes #104. #104
  • Validate objects in pipedKeyValues. Closes #105. #105

Commits

0.4.2 - 2017-07-03

Commits

  • Mark places radar search as deprecated. 0ce041c
  • Version 0.4.2 fafd754

0.4.1 - 2017-06-14

Fixed

  • Broader API support in isSuccessful/canRetry handlers. Closes #100. #100

Commits

0.4.0 - 2017-06-09

Merged

  • Exclude false values from params #98
  • Cleanup NPM package #93
  • Geolocation #81
  • Add input data to output data. #91
  • Update docs on proper usage of asPromise() #90
  • Use local https agent, instead of dirtying global agent #95
  • Fixed handling multibyte encoding responses #87
  • speed up response by 4x fold #83
  • Remove memory leak in Task. #75
  • Fix InvalidValueError to include the message in the stack trace. #67

Fixed

  • Fix places autocomplete param, type -> types. Closes #92. #92
  • Add strictbounds param to places API. Closes #74. #74
  • Remove memory leak in Task. Fixes #71 #71
  • Support per-client language param. Closes #64. #64

Commits

  • Geolocation amendments 5ef38ec
  • Add gelocation API d550a72
  • Support JSON over HTTP POST in prep for geolocation API da36fe1

0.3.1 - 2016-12-01

Merged

  • Provide a way to add extra params to any request. #57
  • Prevent the licenses turning up in the generated jsdoc. #56

Commits

  • Accept ZERO_RESULTS as a successful response. 2c9be2d
  • Cleaner custom params 402f5d6
  • Surface errors when the status is not OK (even though the network layer says OK) 5f8223b

0.3.0 - 2016-10-19

Merged

  • Add query autocomplete and fix places auto complete. Closes #44. #48
  • Updated query.type doc for autocomplete in places.js #47
  • Fix placesNearby rankby parameter #45
  • Properly cancel timers #41

Fixed

  • Add query autocomplete and fix places auto complete. Closes #44. (#48) #44
  • Cancel timeouts when a task is cancelled. #40

Commits

  • Adds Task.race() d031bf7
  • Do proper cancelling of the delays in the throttled queue. 5224e78
  • Use Task.race() to race the timeout and the request. 56a47dc

0.2.1 - 2016-09-16

Merged

  • Fix timestamp conversion to accept Unix time #39
  • Missing apis #37
  • Fix "socket hang up" error #34
  • Add channel parameter to URL #25
  • Update README.md - add places API #29
  • Updates the API key instructions #28
  • Retry responses with status === 'OVER_QUERY_LIMIT' #27
  • Add User-Agent header. #24
  • Distinguish between cancellation and error, add .finally() method #21
  • Add a real timeout option. #20
  • Enable cancelling in-flight requests #19
  • More links in docs home page; better TOC. #18
  • Validation errors should throw an exception synchronously... #17
  • Use jsdoc #15
  • Fix unit tests: rename utils -> convert #13
  • Add more declarative validator logic; remove all logic from the API functions. #9
  • Add validation logic. #8
  • Add throttling (rate-limiting) of requests. #5
  • Remove devDependency on node-fetch #6
  • Add an implementation of exponential backoff #4

Commits

  • WIP: convert task to use resolve, reject, finally d5c2bdf
  • Add copyright and licence to all source files. 2ea0bca
  • Converts each of the API modules from boilerplate methods into config structures. 576e6a6