This example shows loading a map using the [@googlemaps/js-api-loader](https://www.npmjs.com/package/@googlemaps/js-api-loader)

Read the
[documentation](https://developers.google.com/maps/documentation/javascript/load-maps-js-api.md.txt#js-api-loader).
<iframe src="https://maps-docs-team.web.app/samples/js-api-loader-map/dist/" allow="fullscreen; "></iframe>

### TypeScript

```typescript
// Import the needed libraries.
import { setOptions, importLibrary } from '@googlemaps/js-api-loader';

const API_KEY = 'GOOGLE_MAPS_API_KEY';

async function init(): Promise<void> {
    // Set loader options.
    setOptions({
        key: API_KEY,
    });

    // Load the Maps library.
    const { Map } = await importLibrary('maps');

    // Set map options.
    const mapOptions = {
        center: { lat: 48.8566, lng: 2.3522 },
        zoom: 3,
    };

    // Declare the map.
    new Map(document.getElementById('map')!, mapOptions);
}

void init();
```

### JavaScript

```javascript
// Import the needed libraries.
import { setOptions, importLibrary } from '@googlemaps/js-api-loader';

const API_KEY = 'GOOGLE_MAPS_API_KEY';

async function init() {
    // Set loader options.
    setOptions({
        key: API_KEY,
    });

    // Load the Maps library.
    const { Map } = await importLibrary('maps');

    // Set map options.
    const mapOptions = {
        center: { lat: 48.8566, lng: 2.3522 },
        zoom: 3,
    };

    // Declare the map.
    new Map(document.getElementById('map'), mapOptions);
}

void init();
```

### CSS

```css
html,
body {
    height: calc(100vh - 100px);
    padding: 0;
    font-family: Arial, Helvetica, sans-serif;
}

#map {
    height: calc(100vh - 100px);
}

h1 {
    height: 30px;
}

@media screen and (max-width: 600px) {
    h1 {
        font-size: 1.2em;
    }
}
```

### HTML

```html
<html>
    <head>
        <title>@googlemaps/js-api-loader map</title>
        <meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
        <meta charset="utf-8" />
        <link rel="stylesheet" type="text/css" href="./style.css" />
        <script type="module" src="./index.js"></script>
    </head>
    <body>
        <h1>@googlemaps/js-api-loader map</h1>
        <div id="map"></div>
    </body>
</html>
```

### Clone Sample


Git and Node.js are required to run this sample locally. Follow these [instructions](https://docs.npmjs.com/downloading-and-installing-node-js-and-npm)
to install Node.js and NPM. You will also need a [Google Maps API key](https://developers.google.com/maps/documentation/javascript/get-api-key.md.txt).


The following commands clone the repository, install dependencies, and copy the environment file.

```javascript
  git clone https://github.com/googlemaps-samples/js-api-samples.git
  cd js-api-samples
  npm i
  cp .env.template .env
```


Once you copy the environment file, make sure to open the `.env` file and replace `<Insert your own development API key here>` with your actual API key before starting the sample.

```javascript
  cd samples/js-api-loader-map
  npm start
```