---
metadata:
  - name: generator
    content: Diplodoc Platform v5.39.1
alternate:
  - https://yandex.com.tr/dev/jsapi-v2-1/doc/en/v2-1/examples/cases/event_reverse_geocode.md
  - https://yandex.com.tr/dev/jsapi-v2-1/doc/ru/v2-1/examples/cases/event_reverse_geocode.md
---
> **Documentation Index:** Fetch the complete configuration index at https://yandex.com.tr/dev/jsapi-v2-1/doc/en/llms.txt

# Determining the address of a click on the map using reverse geocoding

<iframe id="LIVE-EXAMPLE" style="width:100%;height: 400px;border-radius: 8px;border: 1px solid rgba(92, 94, 102, 0.14);" frameBorder="0" src="https://yastatic.net/s3/front-maps-static/maps-front-jsapi-v2-1/examples/2/out/s3-cases/en/event_reverse_geocode/index.html" allow="fullscreen"></iframe>

<a target="_blank" rel="noopener noreferrer" style="display: inline-block;margin-top: 10px;cursor: pointer;border-radius: 4px;padding: 9px 12px;background: #151515;color: white;text-decoration: none;font-weight: 500" href="https://codesandbox.io/p/sandbox/rtmy7d?file=index.html">Open in CodeSandbox</a>

<div id="references">
    <a href="https://yandex.ru/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/ready">ready</a>, <a href="https://yandex.ru/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/Map">Map</a>, <a href="https://yandex.ru/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/map.Container">map.Container</a>,
    <a href="https://yandex.ru/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/geocode">geocode</a>,
    <a href="https://yandex.ru/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/map.GeoObjects">map.GeoObjects</a>, <a href="https://yandex.ru/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/GeoObjectCollection">GeoObjectCollection</a>, <a href="https://yandex.ru/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/Placemark">Placemark</a>,
    <a href="https://yandex.ru/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/Event">Event</a>
</div>
    <p>
     In the example, when the map is clicked, a placemark appears with the address of the point that was clicked.
    </p>
<p>
    Here two events are listened for: a click on the map and dragging the marker. When one of them occurrs, a request is sent to the geocoder with the coordinates of the point at which the event occurred. The resulting address is recorded as the placemark content.
</p>

{% list tabs %}

-   index.html

    ```html
      <!DOCTYPE html>

    <head>
        <title>Examples. Determining the address of a click on the map using reverse geocoding</title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <!--
            Set your own API-key. Testing key is not valid for other web-sites and services.
            Get your API-key on the Developer Dashboard: https://developer.tech.yandex.ru/keys/
        -->
        
        
        
    </head>
    <body>
    <p class="header">Click on the map to get the address</p>
    <div id="map"></div>
    </body>
    </html>
    ```

-   event_reverse_geocode.js

    ```js
    ymaps.ready(init);

    function init() {
        var myPlacemark,
            myMap = new ymaps.Map(
                "map",
                {
                    center: [55.753994, 37.622093],
                    zoom: 9,
                },
                {
                    searchControlProvider: "yandex#search",
                }
            );

        // Listening for a click on the map
        myMap.events.add("click", function (e) {
            var coords = e.get("coords");

            // Moving the placemark if it was already created
            if (myPlacemark) {
                myPlacemark.geometry.setCoordinates(coords);
            }
            // Otherwise, creating it.
            else {
                myPlacemark = createPlacemark(coords);
                myMap.geoObjects.add(myPlacemark);
                // Listening for the dragging end event on the placemark.
                myPlacemark.events.add("dragend", function () {
                    getAddress(myPlacemark.geometry.getCoordinates());
                });
            }
            getAddress(coords);
        });

        // Creating a placemark
        function createPlacemark(coords) {
            return new ymaps.Placemark(
                coords,
                {
                    iconCaption: "searching...",
                },
                {
                    preset: "islands#violetDotIconWithCaption",
                    draggable: true,
                }
            );
        }

        // Determining the address by coordinates (reverse geocoding).
        function getAddress(coords) {
            myPlacemark.properties.set("iconCaption", "searching...");
            ymaps.geocode(coords).then(function (res) {
                var firstGeoObject = res.geoObjects.get(0);

                myPlacemark.properties.set({
                    // Forming a string with the object's data.
                    iconCaption: [
                        // The name of the municipality or the higher territorial-administrative formation.
                        firstGeoObject.getLocalities().length
                            ? firstGeoObject.getLocalities()
                            : firstGeoObject.getAdministrativeAreas(),
                        // Getting the path to the toponym; if the method returns null, then requesting the name of the building.
                        firstGeoObject.getThoroughfare() ||
                            firstGeoObject.getPremise(),
                    ]
                        .filter(Boolean)
                        .join(", "),
                    // Specifying a string with the address of the object as the balloon content.
                    balloonContent: firstGeoObject.getAddressLine(),
                });
            });
        }
    }
    ```

{% endlist %}
