Polygon Auto-Completion

This example creates a map with a simple polygon, to demonstrate the autoclose behavior for polygons. Note that only three coordinates are defined. There's no need to specify the final coordinates to complete the polygon, because the Google Maps JavaScript API will automatically draw the closing side.

Read the documentation.

Try Sample

Clone Sample

Git and Node.js are required to run this sample locally. Follow these instructions to install Node.js and NPM. The following commands clone, install dependencies and start the sample application.

  git clone -b sample-polygon-autoclose https://github.com/googlemaps/js-samples.git
  cd js-samples
  npm i
  npm start

Other samples can be tried by switching to any branch beginning with sample-SAMPLE_NAME.

  git checkout sample-SAMPLE_NAME
  npm i
  npm start