Non-Javascript LocalSearch

May 16, 2008

I wrote a non-Javascript version of Google Maps which is designed to show how easy it is to write an application on App Engine that makes use of two new APIs from Google: The Static Maps API and the Local Search API's REST interface. It doesn't have fancy stuff like street view and public transportation, but it gives you a searchable map that you can zoom in/out on as well as save locations. It also automatically saves your last map view so that every time you go back to the site it will show you what you were last looking at. Check out the source code.

It uses App Engine to store saved points, the AJAX LocalSearch REST API for search functionality, and the Static Maps API to display maps. I really enjoyed working with App Engine. It's free, easy to learn and the data store is very useful. Likewise, using the REST LocalSearch is beyond simple. Here's all you have to do in Python to retrieve search results:

query = urllib.urlencode({'q' : 'pizza near mountain view'})
url = 'http://ajax.googleapis.com/ajax/services/search/local?v=1.0&%s&rsz=large' \
% (query)
local_search_points = urlfetch.fetch(url)
json = simplejson.loads(local_search_points.content)
points = json['responseData']['results']
for i in points:
# output the information e.g. i['streetAddress']
To use the Static Map API, you just need to create a URL with the proper parameters for your desired map view. Keep in mind that you need to set the zoom level (unless you are specifying multiple points -- then it's calculated for you). In the vast majority of cases, this is completely fine. In my case, though, I needed to know what the zoom level was for multiple points and calculate it in cases where I only had one map point.

Here's the code to do this. From line 130 to about 296 you'll find the necessary functions to calculate a zoom level given a bounding box or a set of latitude/longitude points.

It's time to start cranking out those App Engine & AJAX APIs apps!