-1
내가 선택한 특정 국가에서만 주소를 얻고 싶습니다. 내 코드 :Google지도 api 자동 완성 국가
var country="";
$("select[name='country_id']").change(function() {
co=$("select[name='country_id']").val();
});
function initialize() {
var options={};
if(country){
options = {
types: ['geocode'],
componentRestrictions: {country: country}
};
}else{
options = {
types: ['geocode']
};
}
var input = document.getElementById('address');
var autocomplete = new google.maps.places.Autocomplete(input,options);
google.maps.event.addListener(autocomplete, 'place_changed', function() {
//...
});
}
google.maps.event.addDomListener(window, 'load', initialize);
하지만 내 국가 값은 항상 비어 있습니다. 값을 얻기 위해 국가를 처리하려면 어떻게해야합니까? 도와주세요, 제발. 감사!
'국가 = $ 새로운 나라와 자동 완성마다 시간을 초기화해야합니다. 발 () 대신에'co = $ ("select [name = 'country_id']") val();' –
네,하지만 작동하지 않습니다 :'var country = ""; $ ("select [name = 'country_id']"). (function() { country = $ ("select [name = 'country_id'] '). 함수 init() { 경고 (국가); var input = document.getElementById ('locationTextField'); var autocomplete = new google.maps.places.Autocomplete (input); } google.maps.event.addDomListener (window, 'load', init); '페이지가로드 된 다음 아무 신호도 표시하지 않는 경고가 한 번 표시됩니다. –
도움이되지 않았습니다. –