Graticule, Google and UTF8 are in a boat

I faced a problem recently using Graticule with Google geocoder api. Whenever I check for locations whose name contains accentuated chars (like “Orléans”), I was rewarded with a nice REXML exception telling me google xml was not correct (some tags ending missing).

After about an hour of fight with Graticule, then Open-URI, then Net::HTTP, then StringIO and finally google I discovered the problem : Google Geocoder API send xml response with iso-8859-1 unless you fake being…say “Mozilla/5.0”. No matter you specify Accept or Accept-Charset headers the only way to have the xml as utf8 is sending “User-Agent: Mozilla/5.0”.

In fact it works with different versions :“Mozilla/5.0”, “Mozilla 5.0”, “Mozilla 5.0 (give me utf8 please)”, etc.

So if you want to use Graticule to geolocalize locations with accentuated chars change in graticule’s “rest.rb” (around line 80) :

url.open do |response|

to

url.open('User-Agent' => 'Mozilla 5.0 (Some utf8 please)') do |response|

UPDATE :
Brandon Keepers tackles on this lightning fast and release Graticule 0.2.3, one bug down !!

Fri, 27 Apr 2007 13:12 Posted in ,

  1. By Matt King 27/04/2007 at 18h26


    This is really good to know. I’m starting to support international locations in my app and I’m bound to come across names with accentuated characters. Thanks!

Comment Graticule, Google and UTF8 are in a boat


RSS