[英]geocoder.geocode results cannot be accessed from outside variables
我正在尝试获取 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
class 字段:
public geocoderResults: any[] = [];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.