Google Places

In some time killing procrastination at work, I happened by the new(?) Google Places API, which provides information about the surrounding area based on a given latitude/longitude pair.  Location based information is one of my favorite data sets, so I jumped right in.  I’ve already got a matrix of tools set up that can react to the current location of my phone, which I may detail in a later post, ending with a cgi script on my server.

The API calls for authenticated GET requests, so I started by adding a simple wget call to the aforementioned cgi:

wget -q -O /tmp/places.txt https://maps.googleapis.com/maps/api/place/nearbysearch/xml?key=$apiKey&location=$lat,$lon&sensor=true&radius=$radius&types=$types;

However, for some reason, I couldn’t get wget to properly make the secure request. So, I got a bit serious, and went to perl, my goto for the heavy lifting:

my $req_url = ‘https://maps.googleapis.com/maps/api/place/nearbysearch/xml? key=’.$apiKey.’&location=’.$lat.’,’.$lon.’&sensor=true&radius=’.$radius.’&types=’.$types;

This got me the data, and after a quick parse with LibXML got me what I wanted:

my $parser = XML::LibXML->new();
my $doc = $parser->parse_string($source);
if($doc->exists(‘/PlaceSearchResponse/status’) ) {
foreach my $result ( $doc->findnodes(‘/PlaceSearchResponse/result’)) {
$name = $result->findnodes(‘./name’)->to_literal;
$vicinity = $result->findnodes(‘./vicinity’)->to_literal;
$type = $result->findnodes(‘./type’)->to_literal;
$rating = $result->findnodes(‘./rating’)->to_literal;

From there, i just weed out the crap like convenience stores, fast food, etc. and send a push notification to my phone using C2DM, so I get a note with interesting places around me wherever I go.  It’s a lot like Field Trip for android… but I made it.

In the end, after a few weeks of using it, I was annoyed by the crap that Google has in their places database.  I ended up replacing this tool with one that queries the Foursquare API.

Leave a comment