var currentPosition;
function getCurrentPosition() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function (position) {
currentPosition = [position.coords.latitude, position.coords.longitude];
var myGeoObject = new ymaps.GeoObject({
geometry: {
type: "Point",
coordinates: currentPosition
},
properties: {
iconContent: 'Мое местоположение'
}
}, {
preset: 'twirl#nightStretchyIcon'
});
myMap.geoObjects.add(myGeoObject);
myMap.setCenter(currentPosition, 14, {
checkZoomRange: true
});
});
}
else {
alert("Geolocation API не поддерживается в вашем браузере");
}
}
getCurrentPosition();
console.log(currentPosition);
ICAgICAgIHZhciBjdXJyZW50UG9zaXRpb247CiAgICAgICBmdW5jdGlvbiBnZXRDdXJyZW50UG9zaXRpb24oKSB7CgogICAgICAgICAgICBpZiAobmF2aWdhdG9yLmdlb2xvY2F0aW9uKSB7CgogICAgICAgICAgICAgICAgbmF2aWdhdG9yLmdlb2xvY2F0aW9uLmdldEN1cnJlbnRQb3NpdGlvbihmdW5jdGlvbiAocG9zaXRpb24pIHsKICAgICAgICAgICAgICAgICAgICAgICAgY3VycmVudFBvc2l0aW9uID0gW3Bvc2l0aW9uLmNvb3Jkcy5sYXRpdHVkZSwgcG9zaXRpb24uY29vcmRzLmxvbmdpdHVkZV07CgogICAgICAgICAgICAgICAgICAgICAgICB2YXIgbXlHZW9PYmplY3QgPSBuZXcgeW1hcHMuR2VvT2JqZWN0KHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGdlb21ldHJ5OiB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgdHlwZTogIlBvaW50IiwKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBjb29yZGluYXRlczogY3VycmVudFBvc2l0aW9uCiAgICAgICAgICAgICAgICAgICAgICAgICAgICB9LAogICAgICAgICAgICAgICAgICAgICAgICAgICAgcHJvcGVydGllczogewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGljb25Db250ZW50OiAn0JzQvtC1INC80LXRgdGC0L7Qv9C+0LvQvtC20LXQvdC40LUnCiAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgIH0sIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIHByZXNldDogJ3R3aXJsI25pZ2h0U3RyZXRjaHlJY29uJwogICAgICAgICAgICAgICAgICAgICAgICB9KTsKCgogICAgICAgICAgICAgICAgICAgICAgICBteU1hcC5nZW9PYmplY3RzLmFkZChteUdlb09iamVjdCk7CiAgICAgICAgICAgICAgICAgICAgICAgIG15TWFwLnNldENlbnRlcihjdXJyZW50UG9zaXRpb24sIDE0LCB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBjaGVja1pvb21SYW5nZTogdHJ1ZQogICAgICAgICAgICAgICAgICAgICAgICB9KTsKICAgICAgICAgICAgICAgICAgICB9KTsKCiAgICAgICAgICAgIH0KICAgICAgICAgICAgZWxzZSB7CiAgICAgICAgICAgICAgICBhbGVydCgiR2VvbG9jYXRpb24gQVBJINC90LUg0L/QvtC00LTQtdGA0LbQuNCy0LDQtdGC0YHRjyDQsiDQstCw0YjQtdC8INCx0YDQsNGD0LfQtdGA0LUiKTsKICAgICAgICAgICAgfQogICAgICAgIH0KICAgICAgICAKICAgICAgICBnZXRDdXJyZW50UG9zaXRpb24oKTsKICAgICAgICBjb25zb2xlLmxvZyhjdXJyZW50UG9zaXRpb24pOw==