---
title: "Show elevation on click | JavaScript maps SDK"
description: "Get elevation data in meters by clicking the map."
---

> For AI agents: a documentation index is available at [/llms.txt](https://docs.maptiler.com/llms.txt). Markdown versions of all pages are available by appending .md to any URL.

# Show elevation on click

How to get the elevation in meters from any location. MapTiler [SDK elevation](https://docs.maptiler.com/client-js/#%EF%B8%8F-elevation) functions provide convenient access to get the elevation in meters from any location. It’s possible to look up and compute the elevation from: a single location, provide a batch of points, a GeoJSON LineString or a GeoJSON MultiLineString.

Click on the map to get the elevation at this location

### NPM module setup

```bash
npm install --save @maptiler/sdk
```

#### main.js

```js
import { Map, MapStyle, config } from '@maptiler/sdk';
import '@maptiler/sdk/dist/maptiler-sdk.css';

config.apiKey = 'YOUR_MAPTILER_API_KEY_HERE';
const map = new Map({
    container: 'map',
    style: MapStyle.HYBRID,
    center: [-70.02454, -33.81356],
    zoom: 12
});

map.on('load', function () {
    map.on('click', async function (ev) {
      const {lng, lat} = ev.lngLat;
      //get the elevation at a given position
      const elevatedPosition = await maptilersdk.elevation.at([lng, lat]);
      const popup = new maptilersdk.Popup()
        .setLngLat([lng, lat])
        .setHTML(`<h2>Elevation</h2>
        <h3>${elevatedPosition[2].toFixed(0)} mts</h3>`)
        .addTo(map);
    });
});
```

#### index.html

```html
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="robots" content="noindex">
  <title>Show elevation on click | NPM example</title>
  <link rel="stylesheet" href="./style.css">
</head>
<body>
  <div id="map"></div>
  <script type="module" src="./main.js"></script>
</body>
</html>
```

#### style.css

```css
body {margin: 0; padding: 0;}
#map {position: absolute; top: 0; bottom: 0; width: 100%;}
```

### Basic JavaScript setup

```html
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Elevation at point</title>
<script src="https://cdn.maptiler.com/maptiler-sdk-js/v4.2.0/maptiler-sdk.umd.min.js"></script>
<link href="https://cdn.maptiler.com/maptiler-sdk-js/v4.2.0/maptiler-sdk.css" rel="stylesheet" />
<style>
  body {margin: 0; padding: 0;}
  #map {position: absolute; top: 0; bottom: 0; width: 100%;}
</style>
</head>
<body>

<div id="map"></div>

<script>
    maptilersdk.config.apiKey = 'YOUR_MAPTILER_API_KEY_HERE';
    const map = new maptilersdk.Map({
        container: 'map',
        style: maptilersdk.MapStyle.HYBRID,
        center: [-70.02454, -33.81356],
        zoom: 12
    });

    map.on('load', function () {
        map.on('click', async function (ev) {
          const {lng, lat} = ev.lngLat;
          //get the elevation at a given position
          const elevatedPosition = await maptilersdk.elevation.at([lng, lat]);
          const popup = new maptilersdk.Popup()
            .setLngLat([lng, lat])
            .setHTML(`<h2>Elevation</h2>
            <h3>${elevatedPosition[2].toFixed(0)} mts</h3>`)
            .addTo(map);
        });
    });
</script>
</body>
</html>
```

## Related examples

### [Add elevation profile control](https://docs.maptiler.com/sdk-js/examples/elevation-profile-control-simple/)

Examples

Show elevation profiles for GeoJSON traces using MapTiler.

### [3D terrain map](https://docs.maptiler.com/sdk-js/examples/3d-map/)

Tutorials

Create and display 3D terrain maps on web pages.

### [Get POIs information on click](https://docs.maptiler.com/sdk-js/examples/pois-info/)

Examples

Get POI information by clicking the map.

### [Display a popup on click](https://docs.maptiler.com/sdk-js/examples/popup-on-click/)

Examples

Display a popup when a user clicks a symbol.
