Hide

User-editable Shapes

View this example full screen.

JavaScript
// This example adds a user-editable rectangle to the map.

function initMap() {
  var map = new google.maps.Map(document.getElementById('map'), {
    center: {lat: 44.5452, lng: -78.5389},
    zoom: 9
  });

  var bounds = new google.maps.LatLngBounds(
      new google.maps.LatLng(44.490, -78.649),
      new google.maps.LatLng(44.599, -78.443)
  );

  // Define a rectangle and set its editable property to true.
  var rectangle = new google.maps.Rectangle({
    bounds: bounds,
    editable: true
  });
  rectangle.setMap(map);
}
JavaScript + HTML
<!DOCTYPE html>
<html>
  <head>
    <title>User-editable Shapes</title>
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no">
    <meta charset="utf-8">
    <style>
      html, body {
        height: 100%;
        margin: 0;
        padding: 0;
      }
      #map {
        height: 100%;
      }
    </style>
  </head>
  <body>
    <div id="map"></div>
    <script>
// This example adds a user-editable rectangle to the map.

function initMap() {
  var map = new google.maps.Map(document.getElementById('map'), {
    center: {lat: 44.5452, lng: -78.5389},
    zoom: 9
  });

// [START region_rectangle]
  var bounds = new google.maps.LatLngBounds(
      new google.maps.LatLng(44.490, -78.649),
      new google.maps.LatLng(44.599, -78.443)
  );

  // Define a rectangle and set its editable property to true.
  var rectangle = new google.maps.Rectangle({
    bounds: bounds,
    editable: true
  });
// [END region_rectangle]
  rectangle.setMap(map);
}

    </script>
    <script src="https://maps.googleapis.com/maps/api/js?&callback=initMap&signed_in=true" async defer>
    </script>
  </body>
</html>

Send feedback about...

Google Maps JavaScript API
Need help? Visit our support page.