Gathering detailed insights and metrics for @googlemaps/google-maps-services-js
Gathering detailed insights and metrics for @googlemaps/google-maps-services-js
Gathering detailed insights and metrics for @googlemaps/google-maps-services-js
Gathering detailed insights and metrics for @googlemaps/google-maps-services-js
@googlemaps/js-api-loader
Wrapper for the loading of Google Maps JavaScript API script in the browser
@googlemaps/markerclusterer
Creates and manages per-zoom-level clusters for large amounts of markers.
@googlemaps/url-signature
Sign a URL for Google Maps Platform requests.
@types/google__maps
TypeScript definitions for @google/maps
Node.js client library for Google Maps API Web Services
npm install @googlemaps/google-maps-services-js
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
2,917 Stars
1,139 Commits
644 Forks
94 Watching
8 Branches
66 Contributors
Updated on 28 Nov 2024
Minified
Minified + Gzipped
TypeScript (99.09%)
JavaScript (0.72%)
Shell (0.19%)
Cumulative downloads
Total Downloads
Last day
-6%
53,429
Compared to previous day
Last week
0.9%
295,015
Compared to previous week
Last month
6.3%
1,273,683
Compared to previous month
Last year
36.2%
13,073,587
Compared to previous year
This library is a refactor of a previous version published to @google/maps. It is now being published to @googlemaps/google-maps-services-js.
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.
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.
$ npm install @googlemaps/google-maps-services-js
Below is a simple example calling the elevation method on the client class.
Import the Google Maps Client using TypeScript and ES6 module:
1import {Client} from "@googlemaps/google-maps-services-js";
Alternatively using JavaScript without ES6 module support:
1const {Client} = require("@googlemaps/google-maps-services-js");
Now instantiate the client to make a call to one of the APIs.
1const client = new Client({}); 2 3client 4 .elevation({ 5 params: { 6 locations: [{ lat: 45, lng: -110 }], 7 key: process.env.GOOGLE_MAPS_API_KEY, 8 }, 9 timeout: 1000, // milliseconds 10 }) 11 .then((r) => { 12 console.log(r.data.results[0].elevation); 13 }) 14 .catch((e) => { 15 console.log(e.response.data.error_message); 16 });
The generated reference documentation can be found here. The TypeScript types are the authoritative documentation for this library and may differ slightly from the descriptions.
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
This section discusses the migration from @google/maps to @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). This allows direct access to the transport layer without the complexity that was inherent in the old library. Below are two examples.
@google/maps
):1const googleMapsClient = require('@google/maps').createClient({ 2 key: 'your API key here' 3}); 4 5googleMapsClient 6 .elevation({ 7 locations: {lat: 45, lng: -110} 8 }) 9 .asPromise() 10 .then(function(r) { 11 console.log(r.json.results[0].elevation); 12 }) 13 .catch(e => { 14 console.log(e); 15 });
@googlemaps/google-maps-services-js
):1const client = new Client({}); 2 3client 4 .elevation({ 5 params: { 6 locations: [{ lat: 45, lng: -110 }], 7 key: process.env.GOOGLE_MAPS_API_KEY 8 }, 9 timeout: 1000 // milliseconds 10 }, axiosInstance) 11 .then(r => { 12 console.log(r.data.results[0].elevation); 13 }) 14 .catch(e => { 15 console.log(e); 16 });
The primary differences are in the following table.
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.
1const client = new Client({}); 2 3client 4 .elevation({ 5 params: { 6 locations: [{ lat: 45, lng: -110 }], 7 client_id: process.env.GOOGLE_MAPS_CLIENT_ID, 8 client_secret: process.env.GOOGLE_MAPS_CLIENT_SECRET 9 }, 10 timeout: 1000 // milliseconds 11 }) 12 .then(r => { 13 console.log(r.data.results[0].elevation); 14 }) 15 .catch(e => { 16 console.log(e.response.data.error_message); 17 });
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.
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
29 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 10
Reason
no binaries found in the repo
Reason
security policy file detected
Details
Reason
license file detected
Details
Reason
SAST tool is run on all commits
Details
Reason
0 existing vulnerabilities detected
Reason
dependency not pinned by hash detected -- score normalized to 4
Details
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
Score
Last Scanned on 2024-11-25
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More