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!
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/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With