- #its a zip code - do something
- else
- # Assume it's a UK postcode.
- # Fairly naive regexp is: \w{1,2}\d+\w?\s?\d\w\w
-
+ # Its a zip code - ask geocoder.us
+ # (They have a non commerical use api)
+ Net::HTTP.start('rpc.geocoder.us') do |http|
+ resp = http.get("/service/csv?zip=#{postcode}")
+ data = resp.body.split(/, /) # lat,long,town,state,zip
+ lat = data[0]
+ lon = data[1]
+ redirect_to "/index.html?lat=#{lat}&lon=#{lon}&zoom=14"
+ end
+ elsif postcode.match(/^(\w{1,2}\d+\w?\s*\d\w\w)/)
+ # It matched our naive UK postcode regexp