Google Maps JavaScript API v3

User-editable Shapes

View this example full screen.

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

function initialize() {
  var mapOptions = {
    center: new google.maps.LatLng(44.5452, -78.5389),
    zoom: 9
  };
  var map = new google.maps.Map(document.getElementById('map-canvas'),
      mapOptions);

  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);
}

google.maps.event.addDomListener(window, 'load', initialize);
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, #map-canvas {
        height: 100%;
        margin: 0px;
        padding: 0px
      }
    </style>
    <script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false"></script>
    <script>
// This example adds a user-editable rectangle to the map.

function initialize() {
  var mapOptions = {
    center: new google.maps.LatLng(44.5452, -78.5389),
    zoom: 9
  };
  var map = new google.maps.Map(document.getElementById('map-canvas'),
      mapOptions);

// [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
  });

  rectangle.setMap(map);
// [END region_rectangle]
}

google.maps.event.addDomListener(window, 'load', initialize);

    </script>
  </head>
  <body>
    <div id="map-canvas"></div>
  </body>
</html>

Authentication required

You need to be signed in with Google+ to do that.

Signing you in...

Google Developers needs your permission to do that.