我需要从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 未定义值
答案 0 :(得分:-1)
您需要使用回调函数:
M1-M2-A2-B2-C2-D2