title: IONIC 2 - Cannot retrieve array inside ionViewDidLoad()
body: <p>I want to retrieve places coordinates from restApi and display them on the map.
  I got error : Cannot read property 'length' of undefined</p>
  
  <p>Please help me !
  I want you to tell me how i can get my data in order to add multiple markers.</p>
  
  <p>This is my portion of code</p>
  
  <pre><code>import { Component, ViewChild, ElementRef } from '@angular/core';
  import { NavController, NavParams } from 'ionic-angular';
  import { Geolocation } from '@ionic-native/geolocation';
  import { RestProvider } from '../../providers/rest/rest';
  
  declare var google;
  
  @Component({
    selector: 'page-localisation',
    templateUrl: 'localisation.html',
  })
  export class LocalisationPage {
  
    @ViewChild('map') mapElement: ElementRef;
    map: any;
  
    places: Array&lt;any&gt;;
    errorMessage : string;
  
    constructor(public navCtrl: NavController, public navParams: NavParams, public geolocation: Geolocation, public rest: RestProvider) {
    }
  
    ionViewDidLoad(){
      this.loadMap();
      this.getPlaces();
      this.addPlacesToMap()
      console.log("Length : " + this.places.length) ; //Error Cannot read property 'length' of undefined
    }
  
    getPlaces() {
      this.rest.getPlaces().subscribe(
        places =&gt; this.places = places,
          error =&gt; this.errorMessage = &lt;any&gt;error
      );
    }
  
    loadMap(){
      let latLng = new google.maps.LatLng(-4.066548, 5.356315);
      let mapOptions = {
        center: latLng,
        zoom: 15,
        mapTypeId: google.maps.MapTypeId.ROADMAP
      }
      this.map = new google.maps.Map(this.mapElement.nativeElement, mapOptions);
    }
  
    addPlacesToMap(){
      //...
    }
  
    addInfoWindow(marker, content){
      let infoWindow = new google.maps.InfoWindow({
      });
      content: content
      google.maps.event.addListener(marker, 'click', () =&gt; {
        infoWindow.open(this.map, marker);
      });
    }
  
  }
  </code></pre>