Попробуйте так:
xhr(adress).then(response=>console.log(response));
function xhr(adress) {
const request = (resp) => {
// console.log(resp); // {"response":{"GeoObjectCollection": ...
let obj = JSON.parse(resp); // конвертируем из json в объект js //
obj = obj.response; // {GeoObjectCollection: {…}}
obj = obj.GeoObjectCollection; // {metaDataProperty: {…}, featureMember: Array(1)}
obj = obj.featureMember[0]; // GeoObject: {metaDataProperty: {…}, boundedBy: {…}, Point: {…}}
obj = obj.GeoObject.Point; // {pos: "37.620555 55.741333"}
const coords = obj.pos; // 37.620555 55.741333
return coords;
}
function httpGet(fullUrl) {
return new Promise(resolve=>{
const xhr = new XMLHttpRequest();
xhr.open("GET", fullUrl, true);
xhr.onload=()=>{
resolve(
request(xhr.responseText)
);
};
xhr.send();
});
}
const url = 'https://geocode-maps.yandex.ru/1.x/?';
const apikey = 'xxx&format=json&geocode=';
const fullUrl = url + apikey + adress;
return httpGet(fullUrl);
}