Skip to content

Instantly share code, notes, and snippets.

@sanks
sanks / yandex-maps-example.js
Last active April 2, 2021 07:44
Getting user region and city with Yandex.Maps API
ymaps.ready(function () {
ymaps.geolocation.get({ provider: 'yandex' }).then(function(result) {
var data = result.geoObjects.get(0).properties.get('metaDataProperty').GeocoderMetaData;
var administrativeAreaName = data.AddressDetails.Country.AdministrativeArea.AdministrativeAreaName; // region
if ('SubAdministrativeArea' in data.AddressDetails.Country.AdministrativeArea) {
var localityName = data.AddressDetails.Country.AdministrativeArea.SubAdministrativeArea.Locality.LocalityName; // city
} else {
var localityName = data.AddressDetails.Country.AdministrativeArea.Locality.LocalityName; // city
mandatory = () => {
throw new Error('Missing parameter!');
}
foo = (bar = mandatory()) => {
return bar;
}