从自定义异步函数返回值

时间:2017-08-23 19:07:05

标签: javascript google-maps asynchronous async-await

我需要从google geocode api返回lat-lng坐标,并对其执行某些操作。所以,我的代码看起来像这样:

async function getJson(url){

     try {
           const response = await fetch(url);
           return await response.json();
     }
     catch (err) {
           console.error(err.message);
     }
}
function getLocationForName(address){

      getJson(geoCodeUrl+address+apiKey).then(function(location){

            return location.results[0].geometry.location;
      });
}

someFunc(){
    f['location'] = getLocationForName(city+f['street']+'+'+f['house']);
}

f['location'] alwais 未定义

1 个答案:

答案 0 :(得分:-1)

您需要使用回调函数:

M1-M2-A2-B2-C2-D2
相关问题