2015-01-27 3 views
0

내가 위치 이름의 자동 완성을 제공하기 위해이 코드를 사용 덕분에 Google지도 API에 만 도시 이름을 가져 오기 :Google지도 API 자동 완성

var autocomplete = new google.maps.places.Autocomplete(document.getElementById('adr'));
City : <input id="adr" type="text" class="form-control" value="" > 
 
<script src="http://maps.googleapis.com/maps/api/js?sensor=false&amp;libraries=places" type="text/javascript"></script>

이름이 제공되는 모든 위치를, "파리"와 같은 도시 이름뿐 아니라 "독일", 지역 이름 등의 국가 이름도 포함합니다.

어떻게하면 자동 완성이 가능합니까? 도시 이름은입니까? 즉, 거리 이름, 국가 이름, 지역 이름이 없습니까? 다큐먼트에서의

답변

2

: https://developers.google.com/places/documentation/autocomplete#place_types

var autocomplete = new google.maps.places.Autocomplete(yourHTMLElement, { types: ['(cities)']}); 
+0

감사합니다! 특정 국가로 제한하는 방법과 작성된 도시에서 우편 번호를받는 방법을 알고 계십니까? 예 : Paris -> 75000 – Basj

+0

예, componentRestrictions 속성을 사용합니다. 국가 ISO2 코드를 사용하여 국가 제한을 추가 할 수 있습니다. 당신은 Init'var autocomplete = new google.maps.places.Autocomplete (yourHTMLElement, {types : [ '(cities)', componentRestrictions : {country : 'fr'}})'또는'동적으로'자동 완성으로 초기화 할 수 있습니다. setComponentRestrictions ({country : 'fr'})'. 참고 자료 : https://developers.google.com/maps/documentation/javascript/places-autocomplete#add_autocomplete – NeoPix

0

var autocomplete = new google.maps.places.Autocomplete(
 
    document.getElementById('adr'), 
 
    { 
 
    types: ['(cities)'] 
 
    } 
 
);
City : <input id="adr" type="text" class="form-control" value="" style="width:100%"> 
 
<script src="http://maps.googleapis.com/maps/api/js?sensor=true&amp;libraries=places" type="text/javascript"></script>

관련 문제