私は場所を自動補完して地図上に経路を見つけています。新しい国の価値フォーム選択ボックスで:{iso_country国} google place autocomplete国の変更が制限されています
は、私が選択ボックスの変更 iはオートコンプリート入力をクリアし、オートコンプリート componentRestrictions =を設定して2カ国、米国とAU.Whenと選択ボックスがあります。スクリプトを最初に読み込むと、デフォルトの国はUSで、オートコンプリートでは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);
}
です。