你的代码表明你的地址是一个格式化的字符串,所以
this.address
执行以下操作时将具有格式化字符串:
this.address = results[0].formatted_address;
为了展示同样的东西,你不需要
async
管,你只要做:
<span>{{address}}</span>
异步的
当您使用
Observable
希望直接在模板中使用。
另外,不能使用回调函数并期望
this
作为父类,它将更改为回调函数调用堆栈。使用胖箭头功能
(results, status) => {...}
而不是正常的
function(){}
保留
这
.
return this.mapsAPILoader.load().then(() => {
let latlng = new google.maps.LatLng({ lat: coords.latitude, lng: coords.longitude });
new google.maps.Geocoder().geocode({ 'location': latlng }, (results, status) => {
console.log(status);
if (status === 'OK') {
console.log(results[0].formatted_address);
this.address = results[0].formatted_address;
this.console.log(this.address);
}
})
})