Hello. There is a script with the help of which, when entering the first letters of the city name, a list of cities appears. Everything works great.
Question: How to get the country and city in separate fields input . For example, I enter Moscow , a list appears and I select Moscow, Moscow, Russia , then Russia should appear in the input name="strana" field, and input name="strana" should appear in the input name="gorod" field.
I would be very grateful for the help!
function initialize() { var input = document.getElementById('searchTextField'); var options = { types: ['(cities)'], }; var autocomplete = new google.maps.places.Autocomplete(input, options); google.maps.event.addListener(autocomplete, 'place_changed', function() { var place = autocomplete.getPlace(); //получаем место console.log(place); console.log(place.name); //название места console.log(place.id); //уникальный идентификатор места }); } google.maps.event.addDomListener(window, 'load', initialize); <script src="http://maps.googleapis.com/maps/api/js?key=AIzaSyBsqnZcch_56fMZAFOeO_eSh2nsqqLFWGY&libraries=places"></script> Введите город: <input id="searchTextField" size="50" type="text" /><br /><br /> Страна: <input name="strana" size="50" type="text" /><br /> Город: <input name="gorod" size="50" type="text" /><br />