Documentation
Reference
2.1.50 (current version)
collection
interactivityModel
Interfaces
2.1.52 (release candidate)
collection
interactivityModel
Interfaces

geolocation

Static object.

Provides information about the user's location.

Methods

geolocation()

Methods

NameReturnsDescription
get([options])

vow.Promise

Tries to determine the user's location. Returns the promise object, which will either be confirmed by the object with the field geoObjects or rejected with an error message. The geoObjects field is an instance of GeoObjectCollection. The object that indicates the user's current location will be added to the collection.

Methods details

get

Tries to determine the user's location. Returns the promise object, which will either be confirmed by the object with the field geoObjects or rejected with an error message. The geoObjects field is an instance of GeoObjectCollection. The object that indicates the user's current location will be added to the collection.

Returns Promise object.

Parameters:

ParameterDefault valueDescription
options

Type:

options.autoReverseGeocode true

Type:

If true, geocode the user position automatically; if false, return as it is. If automatic geocoding is used, the object marking the user's current position has the same structure as the result of executing geocode.

options.mapStateAutoApply false

Type:

If true, the map center and zoom level are adjusted automatically to show the current location of the user; if false, nothing happens.

options.provider 'auto'

Type:

Geolocation provider. Accepted values: 'yandex' - geolocation according to the Yandex data, based on the user IP-address; 'browser' - built-in browser geolocation; 'auto' - try to locate the user by all means available and then choose the best value.

options.timeout 30000

Type:

The response time, in milliseconds.

options.useMapMargin true

Type: Boolean

Whether to account for map margins map.margin.Manager when automatically centering and zooming the map.

Examples:

1.

ymaps.geolocation.get({
    // Setting the option for determining a user by IP
    provider: 'yandex',
    // The map is automatically centered by the user's position.
    mapStateAutoApply: true
}).then(function (result) {
    myMap.geoObjects.add(result.geoObjects);
});

2.

ymaps.geolocation.get({
    // Setting the option for detecting location by IP provider: 'yandex',
    // Automatically geocoding the result.
    autoReverseGeocode: true
}).then(function (result) {
    // Taking the data resulting from geocoding the object and outputting it to the console.
    console.log(result.geoObjects.get(0).properties.get('metaDataProperty').getAll());
});