Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Auto Suggest by Country

I'd like to make a search box that returns google auto suggest responses from different countries. I found this great example of recreating an autocomplete search:

http://jsfiddle.net/XxTuA/2/

var suggestCallBack; // global var for autocomplete jsonp
$(document).ready(function () {
    $("#search").autocomplete({
        source: function(request, response) {
            $.getJSON("http://suggestqueries.google.com/complete/search?callback=?",
                { 
                  "hl":"en", // Language                  
                  "jsonp":"suggestCallBack", // jsonp callback function name
                  "q":request.term, // query term
                  "client":"youtube" // force youtube style response, i.e. jsonp
                }
            );
            suggestCallBack = function (data) {
                var suggestions = [];
                $.each(data[1], function(key, val) {
                    suggestions.push({"value":val[0]});
                });
                suggestions.length = 5; // prune suggestions list to only 5 items
                response(suggestions);
            };
        },
    });
});

but I can't figure out how to limit it to a specific country, and there doesn't seem to be documentation of paramaters that can be passed to google auto suggest.

If anyone has suggestions on how to accomplish this, that would be great. Thanks!

like image 309
christopher Avatar asked Feb 13 '13 20:02

christopher


1 Answers

Autocomplete search suggestions are determined by language not by country.

Just set the hl to a different language.

For more info see this fiddle: http://jsfiddle.net/ArtBIT/x8yfm/

like image 168
ArtBIT Avatar answered Dec 04 '22 12:12

ArtBIT