From: Peter Song Date: 2010-03-20T08:02:44+09:00 Subject: Re: Geocoder My last post wasn't actually relevant to ruby so here's a little snippet using ruby, sqlite and worldkit. I'm just learning ruby myself so this might not be the best way to do this. require 'open-uri' require 'sqlite3' # make a table with two records, Dallas, TX and Lansing, MI database = SQLite3::Database.new( "cities.database" ) database.execute( "create table city_names (id INTEGER PRIMARY KEY, name TEXT, state TEXT, country TEXT, latitude NUMERIC, long NUMERIC);") database.execute( "insert into city_names (name, state, country) values ('Dallas', 'TX', 'US')") database.execute( "insert into city_names (name, state, country) values ('Lansing', 'MI', 'US')") class Geocoder def initialize(db) @db = db @rows = db.execute( "select * from city_names") end def update_coords @link = "" @rows.each do |item| @link = "#{item[1]},#{item[2]},#{item[3]}" open("http://brainoff.com/worldkit/geocoder/rest/?city=#{@link}") do |f| sd = f.read @long = sd.scan(/long>(.*)(.*)