1 | Node.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 |
|
11 | Use Node.js? Want to [geocode][Geocoding API] something? Looking
|
12 | for [directions][Directions API]?
|
13 | This library brings the [Google Maps API Web Services] to your Node.js
|
14 | application. ![Analytics](https://maps-ga-beacon.appspot.com/UA-12846745-20/google-maps-services-js/readme?pixel)
|
15 |
|
16 | The Node.js Client for Google Maps Services is a Node.js Client library
|
17 | for 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 |
|
27 | Keep in mind that the same [terms and conditions](https://developers.google.com/maps/terms)
|
28 | apply to usage of the APIs when they're accessed through this library.
|
29 |
|
30 | ## Attention!
|
31 |
|
32 | 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.
|
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 |
|
49 | Create a new client object by calling `createClient()`
|
50 |
|
51 | ```js
|
52 | const googleMapsClient = require('@google/maps').createClient({
|
53 | key: 'your API key here'
|
54 | });
|
55 | ```
|
56 |
|
57 | Make requests to the Google Maps APIs by calling methods on the client object.
|
58 |
|
59 | ```js
|
60 | // Geocode an address.
|
61 | googleMapsClient.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 |
|
70 | You may use promise-based solution also.
|
71 |
|
72 | ```js
|
73 | const googleMapsClient = require('@google/maps').createClient({
|
74 | key: 'your API key here',
|
75 | Promise: Promise
|
76 | });
|
77 |
|
78 | googleMapsClient.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 |
|
88 | For more usage examples, check out [the tests](spec/e2e/).
|
89 |
|
90 | View the [reference documentation](https://googlemaps.github.io/google-maps-services-js/docs/)
|
91 |
|
92 | Additional documentation for the included web services is available at
|
93 | https://developers.google.com/maps/.
|
94 |
|
95 | ## API keys
|
96 |
|
97 | Each 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 |
|
99 | When you have an API key, you can create a client object:
|
100 |
|
101 | ```js
|
102 | var googleMapsClient = require('@google/maps').createClient({
|
103 | key: 'your API key here'
|
104 | });
|
105 | ```
|
106 |
|
107 | ### Client IDs
|
108 |
|
109 | Google Maps APIs Premium Plan customers can use their [client ID and secret][clientid] to authenticate,
|
110 | instead of an API key.
|
111 |
|
112 | ```js
|
113 | var 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 |
|
123 | Community-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 |
|
129 | In order to run the end-to-end tests, you'll need to supply your API key via an
|
130 | environment variable.
|
131 |
|
132 | $ export GOOGLE_MAPS_API_KEY=AIza-your-api-key
|
133 | $ npm test
|
134 |
|
135 | ## Support
|
136 |
|
137 | This library is community supported. We're comfortable enough with the
|
138 | stability and features of the library that we want you to build real
|
139 | production applications on it. We will try to support, through Stack
|
140 | Overflow, the public surface of the library and maintain
|
141 | backwards compatibility in the future; however, while the library is in
|
142 | version 0.x, we reserve the right to make backwards-incompatible
|
143 | changes. If we do remove some functionality (typically because better
|
144 | functionality exists or if the feature proved infeasible), our intention
|
145 | is to deprecate and give developers a year to update their code.
|
146 |
|
147 | If 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 |
|
153 | Installing via npm also provides the `googlemaps` command-line utility,
|
154 | which 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/
|