Web Search in Your Country
October 12th, 2009 | Published in Google Ajax API
I am happy to announce the addition of the ability to scope your searches to a specific country in the AJAX Web Search API. Now, if you have a lot of visitors in Madagascar, you can make sure that the search results displayed on your site are tailored to them. All it takes is a small change to your code.
There are three possible ways to implement, depending on how you're using the API:
- If you use the loader, you can simply load jsapi on the domain you're interested in (example), such as:
- Alternately, you can set this with the web search object's .setRestriction method (example):
var ws = new google.search.WebSearch();
ws.setRestriction(google.search.Search.RESTRICT_EXTENDED_ARGS,
{'gl' : 'es'}); - Finally, if you're using the RESTful interface, all you have to do is append a "gl" URL parameter to your request:
http://ajax.googleapis.com/ajax/services/search/web?v=1.0&q=flowers&gl=fr
Most valid country codes will work, as long as Google has a home page on that country's top level domain (e.g. google.es). If you use an invalid or unsupported country code, you'll get an error message letting you know.
We're excited to bring you this addition to the API, and look forward to seeing the innovative ways in which you use this new feature to improve your users' experience. Please drop us a line with your thoughts (or questions) on our discussion group.