@googlemaps/google-maps-services-js
Advanced tools
Comparing version 2.0.2 to 2.0.3
@@ -0,1 +1,8 @@ | ||
## [2.0.3](https://github.com/googlemaps/google-maps-services-js/compare/v2.0.2...v2.0.3) (2020-02-27) | ||
### Bug Fixes | ||
* Support a Status of ZERO_RESULTS ([975ce03](https://github.com/googlemaps/google-maps-services-js/commit/975ce03666697f5852d2ec1daed802beb5ddc6b4)) | ||
## [2.0.2](https://github.com/googlemaps/google-maps-services-js/compare/v2.0.1...v2.0.2) (2020-02-08) | ||
@@ -2,0 +9,0 @@ |
@@ -67,3 +67,5 @@ export interface RequestParams { | ||
/** indicates a Distance Matrix request could not be processed due to a server error. The request may succeed if you try again. */ | ||
| "UNKNOWN_ERROR"; | ||
| "UNKNOWN_ERROR" | ||
/** indicates that the request was successful but returned no results. */ | ||
| "ZERO_RESULTS"; | ||
export interface PlacePhoto { | ||
@@ -70,0 +72,0 @@ /** a string used to identify the photo when you perform a Photo request. */ |
{ | ||
"name": "@googlemaps/google-maps-services-js", | ||
"version": "2.0.2", | ||
"version": "2.0.3", | ||
"description": "Node.js client library for Google Maps API Web Services", | ||
@@ -50,5 +50,7 @@ "keywords": [ | ||
"@semantic-release/git": "^9.0.0", | ||
"@semantic-release/github": "^7.0.3", | ||
"@semantic-release/release-notes-generator": "^9.0.0", | ||
"@types/jest": "^24.0.25", | ||
"@types/node": "^12.12.15", | ||
"codecov": "^3.6.1", | ||
"codecov": ">=3.6.5", | ||
"jest": "^24.9.0", | ||
@@ -68,5 +70,5 @@ "semantic-release": "^17.0.2", | ||
"@semantic-release/npm", | ||
"@semantic-release/git" | ||
"@semantic-release/github" | ||
] | ||
} | ||
} |
@@ -42,7 +42,18 @@ Node.js Client for Google Maps Services | ||
Import the Google Maps Client using Typescript and ES6 module: | ||
```js | ||
const maps = new require("@googlemaps/google-maps-services-js"); | ||
import {Client} from "@googlemaps/google-maps-services-js"; | ||
``` | ||
const client = new maps.Client({}); | ||
Alternatively using JavaScript without ES6 module support: | ||
```js | ||
const Client = require("@googlemaps/google-maps-services-js").Client; | ||
``` | ||
Now instantiate the client to make a call to one of the APIs. | ||
```js | ||
const client = new Client({}); | ||
client | ||
@@ -72,2 +83,63 @@ .elevation({ | ||
## Migration | ||
This section discusses the migration from [@google/maps](https://www.npmjs.com/package/@google/maps) to [@googlemaps/google-maps-services-js](https://www.npmjs.com/package/@googlemaps/google-maps-services-js) and the differences between the two. | ||
> **Note**: The two libraries do not share any methods or interfaces. | ||
The primary difference is `@google/maps` exposes a public method that takes individual parameters as arguments while `@googlemaps/google-maps-services-js` exposes methods that take `params`, `headers`, `body`, `instance`(see [Axios](https://github.com/axios/axios)). This allows direct access to the transport layer without the complexity that was inherent in the old library. Below are two examples. | ||
### Old (`@google/maps`): | ||
```js | ||
const googleMapsClient = require('@google/maps').createClient({ | ||
key: 'your API key here' | ||
}); | ||
googleMapsClient | ||
.elevation({ | ||
locations: {lat: 45, lng: -110} | ||
}) | ||
.asPromise() | ||
.then(function(r) { | ||
console.log(r.json.results[0].elevation); | ||
}) | ||
.catch(e => { | ||
console.log(e); | ||
}); | ||
``` | ||
### New (`@googlemaps/google-maps-services-js`): | ||
```js | ||
const client = new Client({}); | ||
client | ||
.elevation({ | ||
params: { | ||
locations: [{ lat: 45, lng: -110 }], | ||
key: process.env.GOOGLE_MAPS_API_KEY | ||
}, | ||
timeout: 1000 // milliseconds | ||
}, axiosInstance) | ||
.then(r => { | ||
console.log(r.data.results[0].elevation); | ||
}) | ||
.catch(e => { | ||
console.log(e); | ||
}); | ||
``` | ||
The primary differences are in the following table. | ||
| Old | New | | ||
| ------------- |:-------------:| | ||
| Can provide params | Can provide params, headers, instance, timeout (see [Axios Request Config](https://github.com/axios/axios#request-config)) | | ||
| API key configured at Client | API key configured per method in params object| | ||
| Retry is supported | Retry is configurable via [axios-retry](https://www.npmjs.com/package/axios-retry) or [retry-axios](https://www.npmjs.com/package/retry-axios) | | ||
| Does not use promises by default | Promises are default | | ||
| Typings are in [@types/googlemaps](https://www.npmjs.com/package/@types/googlemaps) | Typings are included | | ||
| Does not support keep alive | Supports keep alive | | ||
| Does not support interceptors | Supports [interceptors](https://github.com/axios/axios#interceptors)| | ||
| Does not support cancelalation | Supports [cancellation](https://github.com/axios/axios#cancellation) | | ||
## Support | ||
@@ -74,0 +146,0 @@ |
Sorry, the diff of this file is not supported yet
223531
3290
175
11