views:

320

answers:

1

Hi! I've just started using Google's search API to find addresses and the distances between those addresses. I used geopy for this, but, I often had the problem of not getting the correct addresses for my queries. I decided to experiment, therefore, with Google's "Local Search" (http://code.google.com/apis/ajaxsearch/local.html).

Anyway, I wanted to ask if I could use the "Local Search" objects provided by the API within python. Something tells me that I can't and that I have to use json. Does anyone know if there is a work around?

PS: Im trying to make something like this: http://www.google.com/uds/samples/random/lead.html ... except a matrix type deal where the insides will be filled with distances between the addresses.

Thanks for reading!

+2  A: 

As the docs say,

The Google AJAX Search API is a Javascript library that allows you to embed Google Search in your web pages and other web applications. For Flash, and other Non-Javascript environments, the API exposes a raw RESTful interface that returns JSON encoded results that are easily processed by most languages and runtimes.

Python has no trouble processing Json (e.g. with the json module in the standard library in 2.6 and better -- there are also several third party ones e.g. for earlier releases, simplejson being the direct precursor of today's standard json). So it's all about using the RESTful interface correctly, as for most Google APIs not directly wrapped for this or that non-Javascript language.

The code examples here are for Flash, Php, Java, Python, Perl -- they all boil down to visiting a specific URL, e.g. with urllib2 in Python, and processing the returned Json, e.g. with simplejson in (pre-2.6) Python.

All the queries in these RESTful code samples are for a web search, but local search is very similar, just start with the request URL with:

http://ajax.googleapis.com/ajax/services/search/local?v=1.0&q=...

i.e., use local in lieu of web in the URL.

Alex Martelli