【发布时间】:2020-06-08 11:45:25
【问题描述】:
我正在尝试获取 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 以便获取它们的长/纬度?
谢谢!
【问题讨论】:
标签: javascript angular typescript google-maps google-geocoder