2017-10-16 43 views
-2

我在网站上工作...其中当我点击源位置和目标位置输入字段时,它不显示谷歌自动位置....因此,输入字段正在提取结果..但下拉列表不显示..谷歌自动位置下拉列表不显示

我该怎么做..?

我的工作链接是below..you可以看到该链接,并figureout的问题:

我的脚本如下:

<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> 
+0

[发布的代码适用于我(小提琴)](http://jsfiddle.net/geocodezip/dr6q7w69/)。可能是你的关键问题(检查JavaScript控制台)。如果没有,请提供证明问题的[mcve]。 – geocodezip

回答

0

希望这将工作:

自动提示的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>