GoogleMap geocoding challenges


Like most of the programmers that have to deal with languages other than english, I wish we were building english-only web applications, and support only english strings. I live in Quebec and almost all my projects have to deal with the french accents. It obviously brings a lot of challenges when dealing with external systems not using the UTF-8 encoding (like Hotmail for instance which is still on ISO-8859-1, or copy & paste from a French Word document). But I will keep this discussion for another post.

In one of my current projects, I need to integrate GoogleMap in order to get the geocode of a physical address. Piece of cake you would say: just use the google-geocode gem. Well, I tried. It worked really great until I tried searching for a Quebec address with french accents. It failed!

I then told myself that it wasn’t that complicated to implement it myself. I just query Google using a URL like and voila, you get JSON results and simply have to parse it. Well, it is not that straight forward. Here’s what I found:

  • By default, Google replies using the ISO-8859-1 encoding. The JSON parser doesn’t like that. To force UTF-8, you have to pass an extra parameter in the URL: oe=utf8. Where did I get this? From the bug list of the API.
  • The results that Google sends back are not the same as the ones you get from a manual search on Why? I don’t know. I guess the web site does additional massaging to the results.
  • Results may contain some strange things. For example, it you search for “455 st-pierre, montreal, qc, canada”, you get more than one address and one of them is in the Matawinie sub-administrative area, in the Montreal locality, which doesn’t make any sense. So which one is the right one? Well, the machine can’t figure it out, we have to ask the human in front of the computer to pick the right one.
  • You sometimes get results that do not start with a numeric address (it looks like a generic geocode for the street only). I simply convert the address to an integer (bla.to_i), and if it returns something higher than 0, than I consider this address as a potential good one.

So I hope this saves you some time if you ever have to do some geocoding mapping in your application.

Thanks for listening! đŸ˜‰

P.S. I just found out that 3 days ago a new version of GeoX got out. I will give this plugin a try to see if it works as I would like it to work. I will post an update soon.


Textmate shortcuts

Oh my god. I finally found the shortcut I was missing for so long: Ctrl-Shift-T. It brings a list of all the methods in the class I’m currently editing. Man, I was dreaming about this feature almost every night. Everyday we learn something, so this is what I learned today (among other things of course!).

By the way, I found this while watching PeepCode’s Textmate Screencast. Lots of interesting screencasts on And for free quick and dirty (and very effective) ones: If you’ve never looked at those, go there right now! You WILL learn something, garanteed! You can even subscribe to those podcasts in iTunes and have them transferred to your iPod (or iPhone).

That’s it! Long live Textmate! Long live RailsCasts & PeepCode.

Concatenating strings

I was looking at some podcasts and Ryan is using an interesting way to concatenate 2 strings, using an array and a join operation.

def full_name
  [first_name, last_name].join(' ')

Now, I was wondering if this was a bit overkill since it has to allocate an Array, then loop through it and build the string. So I ran Benchmark on three different ways to concatenate.

require 'benchmark'
include Benchmark

def using_array(a,b)
  [a,b].join(' ')

def using_format(a,b)
  "#{a} #{b}"

def using_concat(a,b)
  a+' '+b

Benchmark.benchmark " "*7 + CAPTION, 7, FMTSTR do |x|
  a = 'We all'
  b = 'love Ruby on Rails'

  n = 300000"Array: ") { n.times do; using_array(a,b); end }"Format:") { n.times do; using_format(a,b); end }"Concat:") { n.times do; using_concat(a,b); end }

And the results speaks for themselves. As in other languages, the less memory allocations you do, the more performance you will get.

             user     system      total        real
Array:   1.810000   0.020000   1.830000 (  2.395285)
Format:  1.450000   0.010000   1.460000 (  1.634995)
Concat:  1.670000   0.020000   1.690000 (  1.974156)

As you can see, using the format string is really a better approach and I find it easier to read as well.

iPhone review


It’s been a week now that I have my iPhone. Like oncle Tom would say, it is simply “unnnnnbelievable”. Like mac OS X, everything is really well integrated. You see a phone number on a web page, in your adress book, in an SMS message and you simply click on it to make a call. Same thing with an e-mail address.

Talking about email: you can set up multiple accounts (POP, IMAP) and it just works! If you configure them to send your emails through instead of your ISP relay, you can then send e-mails from anywhere in the world, as long as you are on a WiFi network.

The YouTube app is really addictive: easy to navigate and use, and the video quality matches the one on a regular PC.

The web browser (Safari) is a lot better than I thought. The screen being smaller than my Nokia n800, I had a fear that it would be really hard to read and interact with the web site. But the browser has an amazing intelligent zooming feature: when you double-click on a page area, it analyses the HTML code and will zoom just enough so that the element is properly shown within the screen. So if you double-click on a table cell, the browser will zoom that cell. You can then swipe your finger up and down to scroll the page, and this is also well done: the movement is processed so that the scrolling follows an axis. Good job Apple!

But the best is the sync feature. If you are on a Mac, it is transparent. You can sync ALL your contacts (not just a few of them), same thing with your iCal appointments. And if you have long notes in an appointment, it will transfer! And if you want, it can even synchronize your Safari bookmarks.

And….the screen does not scratch…. finally!

But, there are a few things that I miss from my previous Sony Ericson cell phone:

  • Video recording (only pictures)
  • French language (auto-completion is english only and it sometimes gets in the way)
  • SMS templates (you always have to write a message from scratch
  • No games! But I guess this will change soon.
  • Bluetooth access (it only supports earphones, so you can’t exchange contacts or access its content from your notebook)
  • Custom ringtones. You have to buy ringtones iTunes, you just can’t take an MP3 and use it as a ringtone.
  • No WAP support. I know, WAP might be dead right now, but it was a great way to have a very light web site.

So at 399$, it is a must for anyone who wants to stay in touch with his or her digital life when on the road.

Refactor my code

Marc-André Cournoyer had a great idea: allow developpers to exchange on pieces of code, in a friendly matter so that everyone can be proud of their piece of code. The web site is called Refactor My Code. Go have a look. You can share your knowledge of Ruby, PHP, Javascript, Java, C, C#, Python, Perl, Lisp and Bash.

I briefly discussed with Marc-André at the last Montreal on Rails gathering and he was really happy that people at helping each others in a friendly manner.