我使用的地方自動完成在地圖中找到路線,並工作正常。谷歌的地方自動完成國家對變化的限制
我有兩個國家美國和AU.When一個選擇框選擇框變化 我清除自動完成輸入和設置自動完成 componentRestrictions = {國家:iso_country}與新的國家價值形態的選擇框。
當我第一次加載腳本的默認國家是美國和自動完成不建議從AU的任何地方。 (迄今爲止很好)
當我第一次加載腳本並直接將國家改爲AU時,自動填充是從美國推薦和放置的。 (這不是我想要的)
這裏是我的代碼
/*
* When initialize
* i apply autocomplete to the inputs
*/
if($("#from_place").length)
{
apply_autocomplete($("#from_place")[0],default_iso_code);
}
if($("#to_place").length)
{
apply_autocomplete($("#to_place")[0],default_iso_code);
}
/*
* When the Select Box change
* i apply autocomplete to the inputs again with new iso_country
*/
$(document).on('change','#map_country_id',function()
{
var iso_country = $(this).val();
//clear from/to
$("#from_place").val('');
$("#to_place").val('');
//autocomplete from/to with new country
if($("#from_place").length)
{
apply_autocomplete($("#from_place")[0],iso_country);
}
if($("#to_place").length)
{
apply_autocomplete($("#to_place")[0],iso_country);
}
});
/*
* the function that applies the autocomplete
*
*/
function apply_autocomplete(input,iso_country)
{
var options = {
componentRestrictions: {country: iso_country}
};
var autocomplete = new google.maps.places.Autocomplete(input, options);
autocomplete.bindTo('bounds', map);
}
誰能幫我解決這個問題。