@NastyaG

Google maps api Auto Complete для определенной страны?

Здравствуйте. Хочу на странице взаимодействовать с Google maps api Auto Complete. Есть select со странами.
В зависимости от выбранной страны нужно искать адресс. Не могу понять, как в настройки передать выбранную страну:
<!DOCTYPE html>
<html>
<head>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
    <script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false&libraries=places&key=AIzaSyBQcNRinno7Hp9omOx4P1iPyVe5JzIqQzQ"></script>
</head>
<body>
<label for="locationTextField">Location</label>
<input id="locationTextField" type="text" size="50">

<select class="selCommon" name="country_id">
    <option value="">Select</option>
    <option value="ua">Afghanistan</option>
    <option value="ua">Algeria</option>
    <option value="ua">Argentina</option>
</select>

<script>
    var country="";
    $("select[name='country_id']").change(function () {
        country=$("select[name='country_id']").val();
    });
    function init() {
        var options={
            types: ['geocode'],
            componentRestrictions: {country: country}
        };
        var input = document.getElementById('locationTextField');
        var autocomplete = new google.maps.places.Autocomplete(input);
    }
    google.maps.event.addDomListener(window, 'load', init);
</script>
</body>
</html>


Но так ничего не работает, в country у меня пусто. Как это исправить можно? Заранее спасибо!
  • Вопрос задан
  • 182 просмотра
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы