Default Controls

This example creates a map with the default controls.


function initMap(): void {
  const map = new google.maps.Map(
    document.getElementById("map") as HTMLElement,
      center: { lat: -34.397, lng: 150.644 },
      zoom: 8,

declare global {
  interface Window {
    initMap: () => void;
window.initMap = initMap;


function initMap() {
  const map = new google.maps.Map(document.getElementById("map"), {
    center: { lat: -34.397, lng: 150.644 },
    zoom: 8,

window.initMap = initMap;


 * Always set the map height explicitly to define the size of the div element
 * that contains the map. 
#map {
  height: 100%;

 * Optional: Makes the sample page fill the window. 
body {
  height: 100%;
  margin: 0;
  padding: 0;


    <title>Default Controls</title>
    <script src=""></script>

    <link rel="stylesheet" type="text/css" href="./style.css" />
    <script type="module" src="./index.js"></script>
    <div id="map"></div>

      The `defer` attribute causes the callback to execute after the full HTML
      document has been parsed. For non-blocking uses, avoiding race conditions,
      and consistent behavior across browsers, consider loading using Promises.
      for more information.

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-control-default
  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