====== Go Up ====== ===== Description ===== Asks Google Maps for the coordinates of a scpecified position e.g. "Siegessäule Berlin" or "Saalbaustraße 7a 64283 Darmstadt" and displays it in Openstreetmap. Until now, this is much faster and complete than the builtin Openstreetmap search functionality. ===== Perl ===== #!/usr/bin/perl use WWW::Mechanize; use XML::XPath; my ($config,$pid,$xid,$fifo,$socket,$url,$title,@cmd) = @ARGV; if($fifo eq "") { die "No fifo"; }; my $url = "http://maps.google.com/maps/geo?q=@cmd&output=kml"; my $browser = WWW::Mechanize->new(); # download the json page: $browser->get( $url ); my $content = $browser->content(); my $xp = XML::XPath->new($content); my $nodeset = $xp->find('//coordinates'); my $lat; my $lon; foreach my $node ($nodeset->get_nodelist) { my @coord = split(/,/, $node->string_value); $lon = @coord[0]; $lat = @coord[1]; } $dest = "http://www.openstreetmap.org/?lat=$lat&lon=$lon&zoom=14&layers=B000FTF"; qx(echo "uri $dest" >> $fifo); ==== Installation ==== Copy the above script to a directory of your choice and bind it for example with: bind osm _ = spawn $XDG_DATA_HOME/uzbl/scripts/gmapsfind.pl ===== Doesn't seem to work ===== Something goes awry along the way, OSM is called with empty coordinate fields. However, it appears that google also conveniently provides a json view to maps: # curl "http://maps.google.com/maps/geo?q=Amsterdam&output=json" produces the following output { "name": "Amsterdam", "Status": { "code": 200, "request": "geocode" }, "Placemark": [ { "id": "p1", "address": "Amsterdam, The Netherlands", "AddressDetails": { "Accuracy" : 4, "Country" : { "AdministrativeArea" : { "AdministrativeAreaName" : "North Holland", "Locality" : { "LocalityName" : "Amsterdam" } }, "CountryName" : "The Netherlands", "CountryNameCode" : "NL" } }, "ExtendedData": { "LatLonBox": { "north": 52.4282634, "south": 52.3192708, "east": 5.0189941, "west": 4.7628753 } }, "Point": { "coordinates": [ 4.8909347, 52.3738007, 0 ] } } ] } Maybe this serves as a better starting point for scripts? ===== Python version ===== As suggested, working with Google's json output. #!/usr/bin/env python import simplejson, urllib, sys url = 'http://maps.google.com/maps/geo?q=%s&output=json' % sys.argv[-1] result = simplejson.load(urllib.urlopen(url)) lon = result['Placemark'][0]['Point']['coordinates'][0] lat = result['Placemark'][0]['Point']['coordinates'][1] #dest = 'http://www.openstreetmap.org/?lat=%s&lon=%s&zoom=14&layers=B000FTF' % (lat, lon) dest = 'http://www.openstreetmap.org/?lat=%s&lon=%s&zoom=12' % (lat, lon) fifo = open(sys.argv[4], "a") fifo.write("uri " + dest + "\n") fifo.close Example binding: @cbind \\osm_ = spawn $XDG_DATA_HOME/uzbl/scripts/gmapsfind.py \@\@ //Working as of 2010-12-21//