我正在尝试获取google.maps.GeocodeResults,以便我可以访问地址的经度和纬度,以便将其推送到外部Array<any>
变量。
[下面,我能够登录results[0]
,但是当我尝试将其推入数组进行存储时,会得到状态OVER_QUERY_LIMIT
,这对我来说没有意义,因为我已经有了该值。
public geocoderResults!: Array<any>;
public addCodedAddress(address: string): void {
let geocoder = new google.maps.Geocoder();
geocoder.geocode({ address: address }, (results, status) => {
if (status == google.maps.GeocoderStatus.OK && results[0]) {
console.log('this does have something in it', results[0]);
this.geocoderResults.push(results[0]);
console.log(
'this should have something in it, but doesnt ',
this.geocoderResults,
);
} else {
console.warn(
'Geocode was not successful for the following reason: ' +
status,
);
}
});
}
我如何访问这些GeocodeResults,以便我可以获取它们的长号/经度?
谢谢!
您实际上应该初始化您的geocoderResults
类字段:
public geocoderResults: any[] = [];