【问题标题】:Google automatic location dropdown list is not showingGoogle 自动位置下拉列表未显示
【发布时间】:2017-10-16 09:22:26
【问题描述】:

我正在网站上工作......当我点击源位置和目标位置输入字段时,它不会显示谷歌自动位置......因此,输入字段正在获取结果......但是下拉菜单没有显示..

我该怎么办..?

我的工作链接在下面..你可以看到链接,并找出问题:

我的脚本如下:

    <script src="https://maps.googleapis.com/maps/api/js?key=<API KEY>&libraries=places"></script>
<script>
  function init() {
            var options = {
            componentRestrictions: {country: "au"}};
            var input = document.getElementById('locationTextField');
            var input2 = document.getElementById('locationTextField2');var input3 = document.getElementById('location1');
            var input4 = document.getElementById('location2');
            var autocomplete = new google.maps.places.Autocomplete(input,options);
            var autocomplete2 = new google.maps.places.Autocomplete(input2,options);
            var autocomplete3 = new google.maps.places.Autocomplete(input3,options);
            var autocomplete4 = new google.maps.places.Autocomplete(input4,options);
        }

        google.maps.event.addDomListener(window, 'load', init);


    </script>

【问题讨论】:

标签: php forms google-maps-api-3


【解决方案1】:

希望这会奏效:

自动建议的 HTML 输入字段。

<input placeholder="location" onFocus="init(this);">

JS 代码。

var options = {
    types: ['(cities)'],
    componentRestrictions: {country: "in"},
    strictBounds:true
};

function init(input) {
    var autocomplete = new google.maps.places.Autocomplete(input, options);
    autocomplete.addListener('place_changed', function() {
        var place = autocomplete.getPlace();
        console.log(place);
    });
}

<script src="https://maps.googleapis.com/maps/api/js?key=GOOGLE_MAP_API_KEY&libraries=places" async defer></script>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-08-07
    • 2014-08-09
    • 2016-10-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多