Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Node.js client library for Google Maps API Web Services

License

NotificationsYou must be signed in to change notification settings

googlemaps/google-maps-services-js

Repository files navigation

npmReleaseStableTests/Build

codecovsemantic-release

ContributorsLicenseStackOverflowDiscord

Node.js Client for Google Maps Services

Important

Some parts of this library are only compatible withLegacy Services.Using the Legacy Services requires enabling each API on your Google Cloud project by following the direct links:Places API (Legacy),Directions API (Legacy),Distance Matrix API (Legacy).

The newer Google Maps APIs each provide their own npm-package:

Description

This client library brings the following [Google Maps Web Services APIs] to your server-side Node.js applications:

As well as the following legacy APIs:

Requirements

API Key Security

This client library is designed for use in server-side applications.

In either case, it is important to addAPI key restrictions to improve its security. Additional security measures, such as hiding your keyfrom version control, should also be put in place to further improve the security of your API key.

Check out theAPI Security Best Practices guide to learn more.

[!NOTE]This library for server-side onlyAttempting 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, sinceserver-side Node.js applications is the only supported environment for this library.For other environments, try theMaps JavaScript API, which contains a comparable feature set, and is explicitly intended for use with client-side JavaScript.

Usage

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:

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.

constclient=newClient({});client.elevation({params:{locations:[{lat:45,lng:-110}],key:process.env.MAPS_API_KEY,},timeout:1000,// milliseconds}).then((r)=>{console.log(r.data.results[0].elevation);}).catch((e)=>{console.log(e.response.data.error_message);});

Documentation

For more information, see the referencedocumentation. The TypeScript types are the authoritative documentation for this library and may differ slightly from the descriptions.

Developing

In order to run the end-to-end tests, you'll need to supply your API key via anenvironment variable.

$ export MAPS_API_KEY=YOUR_API_KEY$ npm test

Migration

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 takeparams,headers,body,instance(seeAxios). 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)

constgoogleMapsClient=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):

constclient=newClient({});client.elevation({params:{locations:[{lat:45,lng:-110}],key:process.env.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.

OldNew
Can provide paramsCan provide params, headers, instance, timeout (seeAxios Request Config)
API key configured at ClientAPI key configured per method in params object
Retry is supportedRetry is configurable viaaxios-retry orretry-axios
Does not use promises by defaultPromises are default
Typings are in@types/googlemapsTypings are included
Does not support keep aliveSupports keep alive
Does not support interceptorsSupportsinterceptors
Does not support cancelalationSupportscancellation

Premium Plan Authentication

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.

constclient=newClient({});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);});

Contributing

Contributions are welcome and encouraged! If you'd like to contribute, send us apull request and refer to ourcode of conduct andcontributing guide.

Terms of Service

This library uses Google Maps Platform services. Use of Google Maps Platform services through this library is subject to the Google Maps PlatformTerms of Service.

This library is not a Google Maps Platform Core Service. Therefore, the Google Maps Platform Terms of Service (e.g. Technical Support Services, Service Level Agreements, and Deprecation Policy) do not apply to the code in this library.

European Economic Area (EEA) developers

If your billing address is in the European Economic Area, effective on 8 July 2025, theGoogle Maps Platform EEA Terms of Service will apply to your use of the Services. Functionality varies by region.Learn more.

Support

This library is offered via an open sourcelicense. It is not governed by the Google Maps Platform Support [Technical Support Services Guidelines, the SLA, or theDeprecation Policy. However, any Google Maps Platform services used by the library remain subject to the Google Maps Platform Terms of Service.

This library adheres tosemantic versioning to indicate when backwards-incompatible changes are introduced. Accordingly, while the library is in version 0.x, backwards-incompatible changes may be introduced at any time.

If you find a bug, or have a feature request, pleasefile an issue on GitHub. If you would like to get answers to technical questions from other Google Maps Platform developers, ask through one of ourdeveloper community channels. If you'd like to contribute, please check thecontributing guide.

You can also discuss this library on ourDiscord server.

About

Node.js client library for Google Maps API Web Services

Topics

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Packages

No packages published

Languages


[8]ページ先頭

©2009-2025 Movatter.jp