I am pushing the google coordinates into array but if I print console.log(this.markersData) the result is an empty array with objects-->[]
After second click I am getting an array with an object like this [object]
I will need the data of the first array as well. What I am doing wrong?
HTML
<button (click)="addPlace()" > </button>
Angular2 Function
import {Component, Input,OnInit, Output, EventEmitter,ElementRef} from '@angular/core';
import { Http, Headers, RequestOptions } from "@angular/http";
import {Observable} from 'rxjs/Rx';
export class GoogleMapComponent {
markersData:any[] = [];
addPlace(){
this.http.get('https://maps.googleapis.com/maps/api/geocode/json?address=Rom').map((res: any) => res.json())
.subscribe((res: any) => {
// console.log(res.results[0].geometry.location);
var geo = res.results[0].geometry.location;
if(geo != undefined){
this.markersData.push(geo);
}
},
(error: any) => {
console.log(error);
});
}
console.log(this.markersData)
}
