title: How to get geocode latitude and longitude from json google map api in variables by javascript?
body: <p>JSON GEO LOCATION
  <a href="https://maps.googleapis.com/maps/api/geocode/json?address=KOLKATA&amp;key=API_KEY" rel="nofollow">https://maps.googleapis.com/maps/api/geocode/json?address=KOLKATA&amp;key=API_KEY</a></p>
  
  <pre><code>{
         "results" : [
            {
               "address_components" : [
                  {
                     "long_name" : "Kolkata",
                     "short_name" : "Kolkata",
                     "types" : [ "locality", "political" ]
                  },
                  {
                     "long_name" : "Kolkata",
                     "short_name" : "Kolkata",
                     "types" : [ "administrative_area_level_2", "political" ]
                  },
                  {
                     "long_name" : "West Bengal",
                     "short_name" : "WB",
                     "types" : [ "administrative_area_level_1", "political" ]
                  },
                  {
                     "long_name" : "India",
                     "short_name" : "IN",
                     "types" : [ "country", "political" ]
                  }
               ],
               "formatted_address" : "Kolkata, West Bengal, India",
               "geometry" : {
                  "bounds" : {
                     "northeast" : {
                        "lat" : 23.0078201,
                        "lng" : 88.5428696
                     },
                     "southwest" : {
                        "lat" : 22.3436288,
                        "lng" : 88.19430439999999
                     }
                  },
                  "location" : {
                     "lat" : 22.572646,
                     "lng" : 88.36389500000001
                  },
                  "location_type" : "APPROXIMATE",
                  "viewport" : {
                     "northeast" : {
                        "lat" : 23.0078201,
                        "lng" : 88.5428696
                     },
                     "southwest" : {
                        "lat" : 22.3436288,
                        "lng" : 88.19430439999999
                     }
                  }
               },
               "place_id" : "ChIJZ_YISduC-DkRvCxsj-Yw40M",
               "types" : [ "locality", "political" ]
            }
         ],
         "status" : "OK"
      }
  </code></pre>
  
  <p>JS</p>
  
  <pre><code>$(function() {
      $("#home_city_select").change(function() {
          //alert( $('option:selected', this).text() );
          var city = document.getElementById("home_city_select").value;
          var ltd;
          var lng;
  
          var jsonLtdLng="https://maps.googleapis.com/maps/api/geocode/json?address="+city+"&amp;key=API_KEY";
          //alert(JSON.stringify(jsonLtdLng));
          //alert($.getJSON(jsonLtdLng));
          //alert($.getJSON(jsonLtdLng.lat));
          //alert($.getJSON(jsonLtdLng.results.geometry.location.lat));
          //alert($.getJSON(jsonLtdLng.results[0].geometry.location.lat));
          //alert($.getJSON(jsonLtdLng.results[0].geometry.location.lat()));
          alert(jsonLtdLng.results[0].geometry.location.lat());
      });
  });
  </code></pre>
  
  <p>Testing in IBM Worklight.</p>
  
  <p>But I cannot get the latitude and longitude</p>
  
  <p>alert(JSON.stringify(jsonLtdLng));//returns full address</p>
  
  <p>alert($.getJSON(jsonLtdLng));//returns object Object</p>
  
  <p>alert($.getJSON(jsonLtdLng.lat));//returns nothing</p>
  
  <p>alert($.getJSON(jsonLtdLng.results.geometry.location.lat));//returns nothing</p>
  
  <p>alert($.getJSON(jsonLtdLng.results[0].geometry.location.lat));//returns nothing</p>
  
  <p>alert($.getJSON(jsonLtdLng.results[0].geometry.location.lat()));//returns nothing</p>
  
  <p>alert(jsonLtdLng.results[0].geometry.location.lat());//returns nothing</p>