2017-10-16 1 views
-2

웹 사이트에서 작업 중입니다 ... 원본 위치 및 대상 위치 입력 필드를 클릭하면 Google 자동 위치가 표시되지 않습니다 .... 따라서 입력 필드가 가져 오는 중입니다. 그러나 드롭 다운이 표시되지 않습니다 ..Google 자동 위치 드롭 다운 목록이 표시되지 않습니다.

어떻게해야합니까 ..?

내 스크립트는 다음과 같습니다 :

<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/). 키에 문제가있을 수 있습니다 (자바 스크립트 콘솔 확인). 그렇지 않은 경우 문제를 설명하는 [mcve]를 제공하십시오. – geocodezip

답변

0

희망이 작동합니다

내 작업 링크 below..you 링크를 참조하여 문제를 figureout 수있다

자동 제안 용 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>