簡體   English   中英

Google Autocomplete Cities在Wordpress中過濾到英國

[英]Google Autocomplete Cities FIlter to Uk in wordpress

我的網站中出現錯誤圖片,我想將有關城市的google自動完成建議僅限於英國。 但是每當我嘗試僅將其過濾到uk時。 我什至沒有來自全世界或英國的建議。 這是主題內置的wordpress網站搜索。 我在主題目錄中獲得了該代碼。 如果有人可以幫助我對該代碼進行適當的更改以獲得正確的結果,將不勝感激。

function autofilllocation()
{

    $(".location-autocomplete").each(function(){

        var element = $(this).get(0);

        var autocomplete = new google.maps.places.Autocomplete(

            element ,

            { types: ['geocode'] }

        );



        if($(element).hasClass('filter-location')) {

            google.maps.event.addListener(autocomplete, 'place_changed', function() {

                $( document.body ).trigger( 'ajax_filter_search' );

            });

        }

    });

}

幫我PLZ THERE是發生錯誤的圖片。

您應該按國家/地區應用組件限制。 請查看文檔中的自動完成選項對象:

https://developers.google.com/maps/documentation/javascript/3.exp/reference#AutocompleteOptions

在您的代碼中,您可以這樣做:

var autocomplete = new google.maps.places.Autocomplete(
        element ,
        { 
            types: ['geocode'],
            componentRestrictions: {
                country: 'GB'
            }
        }
);

jsbin上的示例: http ://jsbin.com/bomawo/edit?html,輸出

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM