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

# Определение местоположения пользователя

<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/ru/geolocation/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/qprkvv?file=index.html">Open in CodeSandbox</a>

<div id="references">
    <a href="https://yandex.ru/dev/jsapi-v2-1/doc/ru/v2-1/ref/reference/ready">ready</a>, <a href="https://yandex.ru/dev/jsapi-v2-1/doc/ru/v2-1/ref/reference/Map">Map</a>, <a href="https://yandex.ru/dev/jsapi-v2-1/doc/ru/v2-1/ref/reference/map.GeoObjects">map.GeoObjects</a>, <a href="https://yandex.ru/dev/jsapi-v2-1/doc/ru/v2-1/ref/reference/Placemark">Placemark</a>, <a href="https://yandex.ru/dev/jsapi-v2-1/doc/ru/v2-1/ref/reference/geolocation">geolocation</a>
</div>
<p>
    API позволяет <a href="https://yandex.ru/dev/jsapi-v2-1/doc/ru/v2-1/dg/concepts/geolocation">получить информацию
    о предполагаемом местоположении пользователя</a> по IP-адресу или средствами Geolocation API.
</p>
<p>
    Доступ к этим данным предоставляет статический объект <a href="https://yandex.ru/dev/jsapi-v2-1/doc/ru/v2-1/ref/reference/geolocation">geolocation</a>.
</p>

{% list tabs %}

-   index.html

    ```html
    <!DOCTYPE html>
    <html>
        <head>
            <title>Определение местоположения пользователя</title>
            <meta
                http-equiv="Content-Type"
                content="text/html; charset=utf-8"
            />
            <!--
            Укажите свой API-ключ. Тестовый ключ НЕ БУДЕТ работать на других сайтах.
            Получить ключ можно в Кабинете разработчика: https://developer.tech.yandex.ru/keys/
        -->
            
            
            
        </head>
        <body>
            <div id="map"></div>
        </body>
    </html>
    ```

-   geolocation.js

    ```js
    ymaps.ready(init);

    function init() {
        var geolocation = ymaps.geolocation,
            myMap = new ymaps.Map(
                "map",
                {
                    center: [55, 34],
                    zoom: 10,
                },
                {
                    searchControlProvider: "yandex#search",
                }
            );

        // Сравним положение, вычисленное по ip пользователя и
        // положение, вычисленное средствами браузера.
        geolocation
            .get({
                provider: "yandex",
                mapStateAutoApply: true,
            })
            .then(function (result) {
                // Красным цветом пометим положение, вычисленное через ip.
                result.geoObjects.options.set(
                    "preset",
                    "islands#redCircleIcon"
                );
                result.geoObjects.get(0).properties.set({
                    balloonContentBody: "Мое местоположение",
                });
                myMap.geoObjects.add(result.geoObjects);
            });

        geolocation
            .get({
                provider: "browser",
                mapStateAutoApply: true,
            })
            .then(function (result) {
                // Синим цветом пометим положение, полученное через браузер.
                // Если браузер не поддерживает эту функциональность, метка не будет добавлена на карту.
                result.geoObjects.options.set(
                    "preset",
                    "islands#blueCircleIcon"
                );
                myMap.geoObjects.add(result.geoObjects);
            });
    }
    ```

{% endlist %}
