Skip to content

googlemaps-samples/js-api-samples

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1,402 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

js-api-samples

Description

Welcome to the js-api-samples repository, the home of Google Maps JavaScript API documentation samples.

Important Note: Repository Migration in Progress

This repository (js-api-samples) is the new home for the Maps JavaScript API samples.

We are currently migrating all samples from the old repository (js-samples). During this transition, you may find some samples are still missing or under development.

We appreciate your patience as we complete this migration. Please check back regularly for updates.

Try the examples out at Google Maps JavaScript API documentation.

Development

Each example is one atomic unit, for which dependencies must be individually set up.

Environment Setup

  1. Copy the .env.template file to .env:
    cp .env.template .env
  2. Open .env and replace <Insert your own development API key here> with your Google Maps API key. The .env file is already added to .gitignore to prevent accidentally committing your key.

Build samples

  1. Run npm i to install dependencies. You only need to do this once, and thereafter only to update dependencies.
  2. Navigate to the top level (samples/).
  • To build a single sample, run npm run build --workspace=sample-name/
  • To build all samples, run npm run build-all.

Build output is copied to the main dist/ folder. Each individual sample folder also contains a dist/ folder, but this is only used by Vite for live preview.

Run a single sample

  1. Navigate to the folder for the sample you want to run (cd samples/sample-name).
  2. Run npm start to start a server with that sample.

Testing

  • To test, navigate to project root and run npx playwright test. {# TODO: Expand this section. #}

Code Quality Checks

This repository strictly enforces code formatting and best practices using ESLint, Prettier, and custom validation scripts.

Global Checks (check-and-fix)

You can automatically check and fix issues across all samples at once from the root directory:

npm run check-and-fix

This command will:

  1. Run eslint --fix to catch and resolve JavaScript/TypeScript linting errors.
  2. Run prettier -w to format all files (HTML, CSS, TS, JS, JSON) according to the repository's styling rules.
  3. Run tsc --noEmit across all samples to verify TypeScript compilation passes.

Build-time Checks (build-single.sh)

When you build an individual sample using npm run build, the build is handled by samples/build-single.sh. This script enforces several Google Maps Platform best practices before compilation, including:

  • Preventing synchronous await google calls in close proximity (suggesting Promise.all() instead).
  • Verifying that <script> tags correctly reside inside <head> rather than <body>.
  • Ensuring the inline bootstrap loader uses the correct format and does not use hardcoded API keys.
  • Running Prettier, ESLint, and TSC specifically for that sample to ensure it meets quality standards.

Contributing

Contributions are welcome! Please see contributing for more information.

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 Platform Terms 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.

Support

This library is offered via an open source license. It is not governed by the Google Maps Platform Support Technical Support Services Guidelines, the SLA, or the Deprecation Policy (however, any Google Maps Platform services used by the library remain subject to the Google Maps Platform Terms of Service).

This library adheres to semantic 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, please file an issue on GitHub. If you would like to get answers to technical questions from other Google Maps Platform developers, ask through one of our developer community channels. If you'd like to contribute, please check the Contributing guide.

You can also discuss this library on our Discord server.

About

The home of Google Maps JavaScript API documentation samples.

Resources

License

Code of conduct

Contributing

Security policy

Stars

26 stars

Watchers

6 watching

Forks

Packages

 
 
 

Contributors