Reputation: 1234
I am trying to grab google.maps.GeocodeResults so that i can access my address's longitude and latitude so that I can push it to an outside Array<any>
variable.
Below, I am able to log results[0]
, but when i try to push it to an array for storage, i am given the status OVER_QUERY_LIMIT
, which doesn't make sense to me since i already have the value.
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,
);
}
});
}
How can i access these GeocodeResults so i can grab their long / lat?
Thanks!
Upvotes: 0
Views: 209
Reputation: 71961
You should actually initialize your geocoderResults
class field:
public geocoderResults: any[] = [];
Upvotes: 1