title: Extracting data from HTTP Response - Angular 5
body: <p>I am trying to extract lat and lng values form the resulting JSON, from HTTP response - </p>
  
  <pre><code>  lat: any;
    lng: any;
    geoResult: any;
  
    public getGeoCoordinates(store) {
      let apiUrl = '/assets/GoogleGeoCoordinates.json';
      this.http.get(apiUrl).subscribe( resp =&gt; {
          this.geoResult = resp;
      });
    }
  </code></pre>
  
  <p>from above method, I am trying to capture the values as follows</p>
  
  <pre><code>  if (resp['status'] == 'OK' &amp;&amp; resp['results']['length'] &gt; 0) {
          this.lat = resp['results'][0]['geometry']['location']['lat'];
          this.lng = resp['results'][0]['geometry']['location']['lng'];
     }
  </code></pre>
  
  <p>if I use alert(), like alert('Latitude : ' + resp['results'][0]['geometry']['location']['lat']);</p>
  
  <p>alert is showing the value. </p>
  
  <p>If I store that value in 'this.lat' variable, I am getting 'undefined'</p>
  
  <p>can someone help me, to understand to get the values from the json HTTP response</p>
  
  <p>JSON file content - GoogleGeoCoordinates.json</p>
  
  <pre><code>{
      "results": [
          {
              "address_components": [
                  {
                      "long_name": "120",
                      "short_name": "120",
                      "types": [
                          "street_number"
                      ]
                  },
                  {
                      "long_name": "West 56th Street",
                      "short_name": "W 56th St",
                      "types": [
                          "route"
                      ]
                  },
                  {
                      "long_name": "Manhattan",
                      "short_name": "Manhattan",
                      "types": [
                          "political",
                          "sublocality",
                          "sublocality_level_1"
                      ]
                  },
                  {
                      "long_name": "New York",
                      "short_name": "New York",
                      "types": [
                          "locality",
                          "political"
                      ]
                  },
                  {
                      "long_name": "New York County",
                      "short_name": "New York County",
                      "types": [
                          "administrative_area_level_2",
                          "political"
                      ]
                  },
                  {
                      "long_name": "New York",
                      "short_name": "NY",
                      "types": [
                          "administrative_area_level_1",
                          "political"
                      ]
                  },
                  {
                      "long_name": "United States",
                      "short_name": "US",
                      "types": [
                          "country",
                          "political"
                      ]
                  },
                  {
                      "long_name": "10019",
                      "short_name": "10019",
                      "types": [
                          "postal_code"
                      ]
                  }
              ],
              "formatted_address": "120 W 56th St, New York, NY 10019, USA",
              "geometry": {
                  "location": {
                      "lat": 40.7640254,
                      "lng": -73.97896
                  },
                  "location_type": "ROOFTOP",
                  "viewport": {
                      "northeast": {
                          "lat": 40.7653743802915,
                          "lng": -73.97761101970849
                      },
                      "southwest": {
                          "lat": 40.7626764197085,
                          "lng": -73.98030898029151
                      }
                  }
              },
              "place_id": "ChIJE4YK3PlYwokRybTACneYny4",
              "types": [
                  "street_address"
              ]
          }
      ],
      "status": "OK"
  }
  </code></pre>