これは私のコードです:
function geocode(){
var country_code ='us';
// var country_code ='';
// if (country_code) var country_code = read_cookie('country');
// country_code = country_code.toLowerCase();
var GeoCoded = { done: false };
var input = document.getElementById('loc');
var options = { types: [], componentRestrictions: { 'country': country_code } };
これは、ユーザーのコンピューターに保存されているCookie値を取得し、オートサジェストのcomponent_restrictions値に設定するように設計されています。しかし、私が抱えている問題は、ユーザーがCookieを設定していない場合、値が空になることです。componentRestrictionは、そこに値がある場合にのみ機能するようです。
たとえば、この行を使用すると、次のように機能します。
var country_code ='us';
私がこの行を使用する場合、それはしません:
var country_code ='';
Cookieが設定されていない場合、componentRestrictionがないように機能させて、すべての国を自動提案するようにします。これは、このコードを完全に削除した場合にのみ機能するようです。
componentRestrictions: { 'country': country_code } }