opensoul.org

Announcing Graticule geocoding API

update: Graticule is now hosted on Rubyforge.

Graticule is a geocoding API for interpolating address data into geographic coordinates written in Ruby. The goal is to provide a consistent interface into the various geocoding services, allowing other libraries to be built on top of them while remaining agnostic of the specific service that is being used.

In its current state, Graticule is just a repackaging of the different gems produced by Eric Hodel of Robot Co-op. It currently supports the Yahoo, Google, Geocoder.us, and MetaCarta APIs. The plan is to expand upon them.

Usage

You can grab the gem or check out the code from Subversion. The Rdoc is also available.

require 'rubygems'
require 'graticule'
geocoder = Graticule.service(:google).new "api_key"
location = geocoder.locate "1600 Amphitheatre Parkway, Mountain View, CA"

Feedback

I’d love to get your feedback. There are a few places where the API is still not consistent (e.g. Yahoo returns multiple results). I’d also appreciate any help with packaging and releasing as I am a newbie at creating Gems.

geocoding, graticule, and ruby October 31, 2006

1 Comment

  1. Andy Nahapetian Andy Nahapetian June 22, 2007

    First of all, Thanks for this great plugin! in cleans up a lot of my code!
    I found a small bug in the way geocoder.locate works. It calls Graticule::Location.to_s to get the formatted string to send to the geocoding service (I only tested the google service).
    The problem is that the to_s method insert a \n into the string, which makes the google geocoder hiccup with certain geocoding queries and give you geodata (my example was :street => ‘Kampstraße 4’ , :zipcode => ‘20357’, :locality => ‘Hamburg’, :country => ‘DE’). Changeing the to_s method to the following solves the problem:


    module Graticule
    class Location
    def to_s(options = {})
    options = {:coordinates => false, :country => true}.merge(options)
    result = ""
    result << “#{street},” if street
    result << [locality, [region, postal_code].compact.join(" “)].compact.join(”, ")
    result << " #{country}" if options[:country] && country
    result << “\nlatitude: #{latitude}, longitude: #{longitude}” if options[:coordinates] && [latitude, longitude].any?
    result
    end
    end
    end

    Kind regards,
    Andy Nahapetian
    link: nahapetian.com

Post a Comment

Comments use textile. Anonymous comments will be deleted.

My name is Brandon Keepers. I like to build things, usually in Ruby or JavaScript. I work at GitHub and live in Holland, MI.

Popular Posts