Sha256: 0f7f2f9040153c45dc3dc8701da4d713843d2aacaf83d49160fe8e9ba61cb0a2
Contents?: true
Size: 1.47 KB
Versions: 2
Compression:
Stored size: 1.47 KB
Contents
module Graticule #:nodoc: module Geocoder #:nodoc: # A library for lookup of coordinates with http://geo.localsearchmaps.com/ # # See http://emad.fano.us/blog/?p=277 class LocalSearchMaps < Rest def initialize @url = URI.parse 'http://geo.localsearchmaps.com/' end # This web service will handle some addresses outside the US # if given more structured arguments than just a string address # So allow input as a hash for the different arguments (:city, :country, :zip) def locate(params) get params.is_a?(String) ? {:loc => params} : map_attributes(location_from_params(params)) end private def map_attributes(location) #mapping = {:street => :address, :locality => :city, :region => :state, :postal_code => :zip} mapping = {} mapping.keys.inject({}) do |result,attribute| result[mapping[attribute]] = location.attributes[attribute] end end def check_error(js) raise AddressError, "Empty Response" if js.nil? or js.text.nil? raise AddressError, 'Location not found' if js.text =~ /location not found/ end def parse_response(js) returning Location.new do |location| coordinates = js.text.match(/map.centerAndZoom\(new GPoint\((.+?), (.+?)\)/) location.longitude = coordinates[1].to_f location.latitude = coordinates[2].to_f end end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
graticule-0.2.1 | lib/graticule/geocoder/local_search_maps.rb |
graticule-0.2.0 | lib/graticule/geocoder/local_search_maps.rb |