Geocoding with Ruby On Rails and Google Maps

As GoogleMaps now offers geocoding services (which works really fine for European streets !), you can use it in any web application to get coordinates from a given address. The services use REST to send queries, and you can get results in XML or JSON.

I’m currently hacking with RoR, so I first tested geocoding with a short ruby snippet:

 require 'open-uri'  require 'rubygems'  require 'hpricot'  key = 'xxx'  address = "105+avenue+de+la+Republique,+Paris,+France"  url = "http://maps.google.com/maps/geo?q=#{address}&output=xml&key=#{key}"  open(url) do |file|    @body = file.read    doc = Hpricot(@body)    (doc/:point/:coordinates).each do |link|      long, lat = link.inner_html.split(',')    end  end

I used hpricot to parse XML results, and even if it’s designed for HTML it works fine in this use case.

Yet, my initial goal was to automatically get coordinates from any address in a RoR application. I decided to add longitude and latitude properties to the class I wanted to geolocate, and add a before_save method in the model.

 # Get lat, long from address before save  def before_save    require 'open-uri'    address = CGI::escape("#{self.address},#{self.city},#{self.state},#{self.country}")    url = "http://maps.google.com/maps/geo?q=#{address}&output=xml&key=#{key}"    open(url) do |file|      @body = file.read      doc = Hpricot(@body)      (doc/:point/:coordinates).each do |link|        self.longitude, self.latitude = link.inner_html.split(',')      end    end  end

That’s it, every time a user create or edit an instance, its coordinates will be added. Well, I certainly should do more tests, but as my knowledge of ruby and rails is limited at the moment, I’ll start with this. If you think something should be changed, feel free to comment this post :) (btw, can someone tell me why I must use require 'open-uri' here, even if that’s already included in my environment.rb ?)

Maps on Nokia770 ?

I tried to load a Google Map on my Nokia770, but seems it doesn’t work. The script maked the browser freeze, and I can’t navigate through the map. It worked one or two times for the first action on the map but then it freezed again.

I also tried Yahoo maps, but the flash map doesn’t seem to load.

Has anyone manage to make one of those run properly on the N770 ?

(While posting this, I’ve read that others already got the problem)

Firsts steps with Ruby On Rails

As I mentioned before, I planned to rewrite recordShops in Ruby on Rails. Actually, more that rewriting this particular application, I’ll try to write a generic “locate and review” tool, with usual tagging and Google Maps stuff.

So, let’s talk about RoR. I’ve already looked at it before, but started seriously to play with it today. And that’s really cool!

Reading Four Days in Rails and with only a few lines of code, I got an object oriented item/reviews model with the appropriate editing forms.

Nice isn’t it ?

Then, I looked for an authentication plugin and installed auth_manager. This plugin includes e-mail validation of accounts, password reminder, different user levels, protected webpages …

Next step was tagging. Acts_as_taggable seems to be the way to add tag features to items.

I still need to integrate Google Maps (Cartographer plugin uses v1 API so I’ll have to look at its code before making it run with the new one), but at the moment, I’m really impressed with RoR features to easilly write “basic” online apps.

European streets on Google Maps

I’ve just discovered - via dowhatimean.net - that Google Maps now displays European street names!

The API has also be updated (you have to make the changes by yourself if you use it), and also offers nice features as tabbed infos windows or control maps.

I think this integration of European streets is really great, especially for services that allow to get location from maps, which couldn’t be done easilly before for European stuff. Actually, I was waiting for it for a service I’m currently rewriting from ning.com to Ruby on Rails: recordShops. I hope I can write about it (and release) soon.

Finally, I’ve upgraded FOAFMap and already existing maps to handle this new API. Here’s a list of changes you’ll certainly need to make to update your app:

Foaf and Google Maps with foafMap

I mentionned about one month ago I wrote a frontend to RAP, called PHOAF, to easilly query FOAF files in PHP5.

Here’s the app I wanted to hack while starting the lib: foafMap, which displays users found in a FOAF profile on a Google Map.

This first version is really basic, but I plan to improve it in the future[1] (avatars, auto-zoom on main foaf user, expanding network …). And, also that’s a bit slow if you know a lot of people, as it fetch and parse each profile.

Yet, I think that’s another fun way to see how Semantic Web can help to share and re-use data among the Web.

Enjoy !

Notes

[1] Check posts tagged with foafmap from this blog … humm one more thing to add to my todo list: RSS feeds per tags

Comparer GoogleMaps & YahooMaps

Cette application Ning de Jon Aquino permet de comparer en simultané l’affichage d’une zone via GoogleMaps et YahooMaps.

Google semble en général avoir plus d’informations disponibles à présenter, que ce soit sur les noms des rues ou sur les rues elles-mêmes. Par contre, bon point pour Yahoo (version Flash) avec la minicarte de navigation qui permet de se déplacer facilement et de situer le contexte. En plus, ça me rappelle Kick Off :)

Géolocalisation collaborative de groupes

Après avoir testé Frapper Beta, j’ai jeté un oeil à MapBuilder (Beta aussi, c’est la mode on dirait), deux outils reposant sur les Google Maps.

Même si MapBuilder propose des fonctionnalités plus sympas (code pour l’export sur son site, fils RSS …), je n’arrive pas à trouver dans ces outils tout ce qui me plairait d’un système online de géolocalisation collaborative de groupes, notamment:

Bref, j’ai commencé à jouer avec l’API Google Maps, si j’ai un peu de temps, on sait jamais …

Qui bloggue près de chez vous ?

Puisque la géolocalisation est un des sujets du moment, notamment avec les nombreux services basés sur Google Maps, voici comment référencer géographiquement son blog ou son site Web[1] grâce au service GeoURL.

Pour ce faire, il faut ajouter ces 2 lignes à l’entête de la page à indexer:

<meta name="ICBM" content="xxx.xxx,yyy.yyy"> <meta name="DC.title" content="Mon site web">

(où le contenu de la balise meta ICBM correspond à des coordonnées géographiques sous la forme "latitude, longitude", disponibles sur Maporama par exemple), puis référencer son URL via ce formulaire.

A partir de là, non seulement les utilisateurs de votre site pourrons vous localiser (cf icone GeoURL), mais vous pourrez également voir quels sont les internautes situées près de chez vous. Et vous pourrez même combiner cette liste avec une Google Map en utilisant GeoURL to GoogleMaps.

Dans le même registre, 3 services permettant de localiser les visiteurs de votre blog:

Les 2 premiers utilisant encore une fois Google Maps pour représenter les informations.

Notes

[1] Il s’agit plutôt, en général, de référencer l’auteur de la page en question