UNPKG

7.11 kBMarkdownView Raw
1Node.js Client for Google Maps Services
2=======================================
3
4[![Build Status](https://travis-ci.org/googlemaps/google-maps-services-js.svg?branch=master)](https://travis-ci.org/googlemaps/google-maps-services-js)
5[![npm](https://img.shields.io/npm/v/@google/maps.svg)](https://www.npmjs.com/package/@google/maps)
6[![codecov](https://codecov.io/gh/googlemaps/google-maps-services-js/branch/master/graph/badge.svg)](https://codecov.io/gh/googlemaps/google-maps-services-js)
7![GitHub contributors](https://img.shields.io/github/contributors/googlemaps/google-maps-services-js?color=green)
8
9> This library has been deprecated in favor of [@googlemaps/google-maps-services-js](https://www.npmjs.com/package/@googlemaps/google-maps-services-js). Bug fixes will continue, however all new feature development will be on the [master branch](https://github.com/googlemaps/google-maps-services-js) and published to the new library.
10
11Use Node.js? Want to [geocode][Geocoding API] something? Looking
12for [directions][Directions API]?
13This library brings the [Google Maps API Web Services] to your Node.js
14application. ![Analytics](https://maps-ga-beacon.appspot.com/UA-12846745-20/google-maps-services-js/readme?pixel)
15
16The Node.js Client for Google Maps Services is a Node.js Client library
17for the following Google Maps APIs:
18
19 - [Directions API]
20 - [Distance Matrix API]
21 - [Elevation API]
22 - [Geocoding API]
23 - [Places API]
24 - [Roads API]
25 - [Time Zone API]
26
27Keep in mind that the same [terms and conditions](https://developers.google.com/maps/terms)
28apply to usage of the APIs when they're accessed through this library.
29
30## Attention!
31
32This 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.
33
34## Features
35
36 - **Retry on Failure** Automatically retry when intermittent failures occur.
37 That is, when any of the retryable 5xx errors are returned from the API.
38
39 - **Rate-limiting** Requests are rate-limited by the client, which helps
40 prevent reaching the server-enforced rate limit.
41
42## Quick Start
43
44 $ npm install @google/maps
45
46**Note:** You'll need to have npm 2.7.0 or greater installed, since this library is hosted as a
47[scoped package](https://docs.npmjs.com/getting-started/scoped-packages).
48
49Create a new client object by calling `createClient()`
50
51```js
52const googleMapsClient = require('@google/maps').createClient({
53 key: 'your API key here'
54});
55```
56
57Make requests to the Google Maps APIs by calling methods on the client object.
58
59```js
60// Geocode an address.
61googleMapsClient.geocode({
62 address: '1600 Amphitheatre Parkway, Mountain View, CA'
63}, function(err, response) {
64 if (!err) {
65 console.log(response.json.results);
66 }
67});
68```
69
70You may use promise-based solution also.
71
72```js
73const googleMapsClient = require('@google/maps').createClient({
74 key: 'your API key here',
75 Promise: Promise
76});
77
78googleMapsClient.geocode({address: '1600 Amphitheatre Parkway, Mountain View, CA'})
79 .asPromise()
80 .then((response) => {
81 console.log(response.json.results);
82 })
83 .catch((err) => {
84 console.log(err);
85 });
86```
87
88For more usage examples, check out [the tests](spec/e2e/).
89
90View the [reference documentation](https://googlemaps.github.io/google-maps-services-js/docs/)
91
92Additional documentation for the included web services is available at
93https://developers.google.com/maps/.
94
95## API keys
96
97Each Google Maps Web Service request requires an API key. To get an API key, follow the [Get API Key](https://developers.google.com/maps/documentation/javascript/get-api-key#get-the-api-key) instructions in our Maps JS API docs.
98
99When you have an API key, you can create a client object:
100
101```js
102var googleMapsClient = require('@google/maps').createClient({
103 key: 'your API key here'
104});
105```
106
107### Client IDs
108
109Google Maps APIs Premium Plan customers can use their [client ID and secret][clientid] to authenticate,
110instead of an API key.
111
112```js
113var googleMapsClient = require('@google/maps').createClient({
114 clientId: 'Add your client ID here',
115 clientSecret: 'Add your client secret here',
116});
117```
118
119**Important:** This key should be kept secret on your server.
120
121## Typescript
122
123Community-built typings for this library are available in `@types/google__maps` (note the double underscore).
124
125`npm install @types/google__maps`
126
127## Developing
128
129In order to run the end-to-end tests, you'll need to supply your API key via an
130environment variable.
131
132 $ export GOOGLE_MAPS_API_KEY=AIza-your-api-key
133 $ npm test
134
135## Support
136
137This library is community supported. We're comfortable enough with the
138stability and features of the library that we want you to build real
139production applications on it. We will try to support, through Stack
140Overflow, the public surface of the library and maintain
141backwards compatibility in the future; however, while the library is in
142version 0.x, we reserve the right to make backwards-incompatible
143changes. If we do remove some functionality (typically because better
144functionality exists or if the feature proved infeasible), our intention
145is to deprecate and give developers a year to update their code.
146
147If you find a bug, or have a feature suggestion, please
148[log an issue][issues]. If you'd like to contribute, please read
149[How to Contribute][contrib].
150
151## Command-line Interface
152
153Installing via npm also provides the `googlemaps` command-line utility,
154which can then be used to pipe JSON results to other command-line programs:
155
156```
157$ googlemaps directions --origin 'Sydney Town Hall' --destination 'Parramatta, NSW'
158```
159
160[apikey]: https://developers.google.com/maps/faq#keysystem
161[clientid]: https://developers.google.com/maps/documentation/business/webservices/auth
162
163[Google Maps API Web Services]: https://developers.google.com/maps/apis-by-platform#web_service_apis
164[Directions API]: https://developers.google.com/maps/documentation/directions/
165[directions-key]: https://developers.google.com/maps/documentation/directions/get-api-key#key
166[Distance Matrix API]: https://developers.google.com/maps/documentation/distancematrix/
167[Elevation API]: https://developers.google.com/maps/documentation/elevation/
168[Geocoding API]: https://developers.google.com/maps/documentation/geocoding/
169[Time Zone API]: https://developers.google.com/maps/documentation/timezone/
170[Roads API]: https://developers.google.com/maps/documentation/roads/
171[Places API]: https://developers.google.com/places/web-service/
172
173[issues]: https://github.com/googlemaps/google-maps-services-js/issues
174[contrib]: https://github.com/googlemaps/google-maps-services-js/blob/master/CONTRIBUTING.md
175[Maps JavaScript API]: https://developers.google.com/maps/documentation/javascript/