How to extract city, country, latitude and longitude from google places result
<p>I am using the following Google Places script to get the location of the user. I get the full address, but I need to parse the result to get city, country.</p>

<pre><code>&lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
&lt;head&gt;
    &lt;title&gt;Google Places Autocomplete textbox using google maps api&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;script src="https://maps.googleapis.com/maps/api/js?v=3.exp&amp;signed_in=true&amp;libraries=places"&gt;&lt;/script&gt;
&lt;script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.0.0-alpha1/jquery.js"&gt;&lt;/script&gt;
&lt;script type="text/javascript"&gt;
google.maps.event.addDomListener(window, 'load', initialize);
function initialize() {
    var autocomplete = new google.maps.places.Autocomplete(document.getElementById('txtAutocomplete'));
    google.maps.event.addListener(autocomplete, 'place_changed', function () {
        var place = autocomplete.getPlace();
        var location = "&lt;b&gt;Address&lt;/b&gt;: " + place.formatted_address + "&lt;br/&gt;";
        location += "&lt;b&gt;Latitude&lt;/b&gt;: " + place.geometry.location.lat() + "&lt;br/&gt;";
        location += "&lt;b&gt;Longitude&lt;/b&gt;: " + place.geometry.location.lng();
        document.getElementById('lblResult').innerHTML = location;
    });
}
&lt;/script&gt;
&lt;span&gt;Location:&lt;/span&gt;
&lt;input type="text" id="txtAutocomplete" style="width: 300px"     placeholder="Enter your address" /&gt;&lt;br /&gt;&lt;br /&gt;
&lt;label id="lblResult" /&gt;
&lt;/body&gt;
&lt;/html&gt;
</code></pre>

<p>I've tried the below script, but it does not work all the time as in some cases, address format is different.</p>

<pre><code>var city = place.address_components[0] &amp;&amp; place.address_components[0].short_name || '';
        document.getElementById('lblResult').innerHTML = location;
        console.log(city);
</code></pre>