Google maps 谷歌地图api为国家自动完成
我只想得到地址在特定的国家,如果它是选择。我的代码是:Google maps 谷歌地图api为国家自动完成,google-maps,autocomplete,google-maps-autocomplete,Google Maps,Autocomplete,Google Maps Autocomplete,我只想得到地址在特定的国家,如果它是选择。我的代码是: var country=""; $("select[name='country_id']").change(function () { co=$("select[name='country_id']").val(); }); function initialize() { var options={}; if(country){ options =
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);
但我的国家价值总是空的。
我如何处理国家以获得其价值?请帮帮我。谢谢 每次使用新国家/地区
onchange
JS
country=$(“选择[name='country_id'])).val()
而不是co=$(“选择[name='country\u id'])。val()代码>是,但它也不起作用:var country=“”$(“选择[name='country\u id']).change(函数(){country=$(“选择[name='country\u id'])).val();});函数init(){alert(country);var input=document.getElementById('locationTextField');var autocomplete=new google.maps.places.autocomplete(input);}google.maps.event.adddomstener(窗口,'load',init)代码>警报显示页面加载后不显示任何内容的一次。它无助于我在出现问题的地方添加工作示例
var country = "";
$("select[name='country_id']").change(function() {
country = $("select[name='country_id']").val();
$('#searchTextField').attr('placeholder','search form '+$("select[name='country_id'] option:selected").text())
$('#input').show();
initialize()
});
function initialize() {
var input = document.getElementById('searchTextField');
var options = {
componentRestrictions: {
country: country
}
};
var autocomplete = new google.maps.places.Autocomplete(input, options);
google.maps.event.addListener(autocomplete, 'place_changed', function() {
var place = autocomplete.getPlace();
var lat = place.geometry.location.lat();
var long = place.geometry.location.lng();
alert(lat + ", " + long);
});
}