在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):googlemaps/google-maps-services-js开源软件地址(OpenSource Url):https://github.com/googlemaps/google-maps-services-js开源编程语言(OpenSource Language):TypeScript 99.4%开源软件介绍(OpenSource Introduction):Node.js Client for Google Maps Services
Use Node.js? Want to geocode something? Looking for directions? This library brings the Google Maps API Web Services to your Node.js application. 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. Quick Start
Below is a simple example calling the elevation method on the client class. Import the Google Maps Client using Typescript and ES6 module: import {Client} from "@googlemaps/google-maps-services-js"; Alternatively using JavaScript without ES6 module support: const {Client} = require("@googlemaps/google-maps-services-js"); Now instantiate the client to make a call to one of the APIs. const client = new Client({});
client
.elevation({
params: {
locations: [{ lat: 45, lng: -110 }],
key: "asdf",
},
timeout: 1000, // milliseconds
})
.then((r) => {
console.log(r.data.results[0].elevation);
})
.catch((e) => {
console.log(e.response.data.error_message);
}); Reference DocumentationThe generated reference documentation can be found here. The TypeScript types are the authoritative documentation for this library and may differ slightly from the descriptions. DevelopingIn order to run the end-to-end tests, you'll need to supply your API key via an environment variable.
MigrationThis section discusses the migration from @google/maps to @googlemaps/google-maps-services-js and the differences between the two.
The primary difference is
Old ( |
Old | New |
---|---|
Can provide params | Can provide params, headers, instance, timeout (see 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 or retry-axios |
Does not use promises by default | Promises are default |
Typings are in @types/googlemaps | Typings are included |
Does not support keep alive | Supports keep alive |
Does not support interceptors | Supports interceptors |
Does not support cancelalation | Supports cancellation |
Authentication via client ID and URL signing secret is provided to support legacy applications that use the Google Maps Platform Premium Plan. The Google Maps Platform Premium Plan is no longer available for sign up or new customers. All new applications must use API keys.
const client = new Client({});
client
.elevation({
params: {
locations: [{ lat: 45, lng: -110 }],
client_id: process.env.GOOGLE_MAPS_CLIENT_ID,
client_secret: process.env.GOOGLE_MAPS_CLIENT_SECRET
},
timeout: 1000 // milliseconds
})
.then(r => {
console.log(r.data.results[0].elevation);
})
.catch(e => {
console.log(e.response.data.error_message);
});
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.
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论