Sha256: 23067b06fd911a3e3cfd3d164e388db53b2341dab474b286bb9b98597619beb8

Contents?: true

Size: 971 Bytes

Versions: 13

Compression:

Stored size: 971 Bytes

Contents

module Graticule
  module Geocoder

    # Library for looking up coordinates with MetaCarta's GeoParser API.
    #
    # http://labs.metacarta.com/GeoParser/documentation.html
    class MetaCarta < Rest

      def initialize # :nodoc:
        @url = URI.parse 'http://labs.metacarta.com/GeoParser/'
      end

      # Finds +location+ and returns a Location object.
      def locate(location)
        get :q => location.is_a?(String) ? location : location_from_params(location).to_s, :output => 'locations'
      end
      
    private

      def check_error(xml) # :nodoc:
        raise AddressError, 'bad location' unless xml.elements['Locations/Location']
      end

      def parse_response(xml) # :nodoc:
        result = xml.elements['/Locations/Location[1]']
        coords = result.elements['Centroid/gml:Point/gml:coordinates'].text.split ','
        Location.new :latitude => coords.first.to_f, :longitude => coords.last.to_f
      end
      
    end
  end
end

Version data entries

13 entries across 13 versions & 4 rubygems

Version Path
CodeMonkeySteve-graticule-0.2.11 lib/graticule/geocoder/meta_carta.rb
CodeMonkeySteve-graticule-0.2.12 lib/graticule/geocoder/meta_carta.rb
collectiveidea-graticule-0.2.12 lib/graticule/geocoder/meta_carta.rb
pepe-graticule-0.2.11 lib/graticule/geocoder/meta_carta.rb
graticule-0.2.12 lib/graticule/geocoder/meta_carta.rb
graticule-0.2.10 lib/graticule/geocoder/meta_carta.rb
graticule-0.2.6 lib/graticule/geocoder/meta_carta.rb
graticule-0.2.5 lib/graticule/geocoder/meta_carta.rb
graticule-0.2.3 lib/graticule/geocoder/meta_carta.rb
graticule-0.2.4 lib/graticule/geocoder/meta_carta.rb
graticule-0.2.8 lib/graticule/geocoder/meta_carta.rb
graticule-0.2.9 lib/graticule/geocoder/meta_carta.rb
graticule-0.2.7 lib/graticule/geocoder/meta_carta.rb