title: How to get the country code from Google Places API
body: <p>I am trying to use HTML 5 GeoLocation to get longitude and latitude and then use Google Maps API <strong>to get the country code</strong> of that longitude/latitude. Is there any simpler way to get country code from google places api?</p>
  
  <p>I found the solution from this link ==> <a href="https://stackoverflow.com/questions/8941923/getting-country-code-from-google-maps-and-html-5-geolocation">Getting country code from Google Maps and HTML 5 GeoLocation</a>
  to get the country code.</p>
  
  <p>Is there way to get country code directly from google places api without getting latitude and longitude first and then passing to google maps api.</p>
  
  <p>This is the following script that I am using to get the country code from google places api</p>
  
  <pre><code>&lt;script&gt;
  // This example displays an address form, using the autocomplete feature
  // of the Google Places API to help users fill in the information.
  
  var placeSearch, autocomplete;
  var componentForm = {
  street_number: 'short_name',
  route: 'long_name',
  locality: 'long_name',
  administrative_area_level_1: 'short_name',
  country: 'long_name',
  postal_code: 'short_name'
  };
  
  function initAutocomplete() {
    // Create the autocomplete object, restricting the search to geographical
   // location types.
    autocomplete = new google.maps.places.Autocomplete(
    /** @type {!HTMLInputElement}     */(document.getElementById('autocomplete')),
    {types: ['(cities)']});
  
    // When the user selects an address from the dropdown, populate the address
    // fields in the form.
    //autocomplete.addListener('place_changed', fillInAddress);
  
  // Get Latitude and longitude
  
    google.maps.event.addListener(autocomplete, 'place_changed', function () {
          var place = autocomplete.getPlace();
          //document.getElementById('city2').value = place.name;
          document.getElementById('lat').value = place.geometry.location.lat();
          document.getElementById('lng').value = place.geometry.location.lng();
  
      });
  }
  
  // [START region_fillform]
  function fillInAddress() {
   // Get the place details from the autocomplete object.
   var place = autocomplete.getPlace();
  
    for (var component in componentForm) {
     document.getElementById(component).value = '';
     document.getElementById(component).disabled = false;
    }
  
    // Get each component of the address from the place details
   // and fill the corresponding field on the form.
   for (var i = 0; i &lt; place.address_components.length; i++) {
     var addressType = place.address_components[i].types[0];
     if (componentForm[addressType]) {
      var val = place.address_components[i][componentForm[addressType]];
      document.getElementById(addressType).value = val;
    }
    }
    }
    // [END region_fillform]
  
  &lt;/script&gt;
  &lt;script src="https://maps.googleapis.com/maps/api/js?sensor=false&amp;amp;libraries=places&amp;callback=initAutocomplete"
      async defer&gt;&lt;/script&gt;
  </code></pre>