7
Dec

GeoCoding using Ruby


A quick hack to get a location's geo coding

 
 require 'xml-simple'
 require 'net/http'
 
 # Enter the location to get the lat and long
 #
 def yahoo_geo(location)
   host = "api.local.yahoo.com"
   q =  "http://api.local.yahoo.com/MapsService/V1/geocode"
   q << "?appid=wnorrix&location=#{URI.encode(location)}"
   xml = XmlSimple.xml_in(Net::HTTP.get(host, q), {"ForceArray" => false})
   return xml["Result"]
 end

Comments

Post new comment

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <apache>, <c>, <cpp>, <drupal5>, <drupal6>, <java>, <javascript>, <php>, <python>, <ruby>. The supported tag styles are: <foo>, [foo].

More information about formatting options