This is my first time working with REST and XML. My goal is to access Google''s geocoding service using HTTP. Here''s the code I have so far: require ''open-uri'' require ''rexml/document'' include REXML url=''http://maps.google.com/maps/geo?'' address = ''q=1600 Amphitheatre Parkway Mountin View,CA'' address1 = URI.escape(address) googleoutput = ''&output=xml'' googlekey = ''&key=mykey'' result=URI(url+address1+googleoutput+googlekey ).read doc = Document.new result r=doc.elements["/Response/Point"] @googlresult = r.attributes["coordinates"] It works up till this line doc = Document.new result (I''m using IRB to test this BTW) It says undefined when that line is executed. Having never done this before, I don''t know what the issue is. I also know there is a google-geocode gem but I''m trying to understand this so I can customize it a little. Here''s a sample of the XML output: http://www.google.com/apis/maps/documentation/#Geocoding_HTTP_Request I need to get the status code and the coordinates. Any help is greatly appreciated. -- Posted via http://www.ruby-forum.com/.
See examples here http://www.germane-software.com/software/rexml/docs/tutorial.html (google is your friend) On 7/14/06, Chris Williams <chris@designmojo.com> wrote:> > This is my first time working with REST and XML. My goal is to access > Google''s geocoding service using HTTP. Here''s the code I have so far: > > require ''open-uri'' > require ''rexml/document'' > include REXML > url=''http://maps.google.com/maps/geo?'' > address = ''q=1600 Amphitheatre Parkway Mountin View,CA'' > address1 = URI.escape(address) > googleoutput = ''&output=xml'' > googlekey = ''&key=mykey'' > result=URI(url+address1+googleoutput+googlekey ).read > doc = Document.new result > r=doc.elements["/Response/Point"] > @googlresult = r.attributes["coordinates"] > > > It works up till this line doc = Document.new result (I''m using IRB to > test this BTW) > > It says undefined when that line is executed. Having never done this > before, I don''t know what the issue is. I also know there is a > google-geocode gem but I''m trying to understand this so I can customize > it a little. > > Here''s a sample of the XML output: > http://www.google.com/apis/maps/documentation/#Geocoding_HTTP_Request > > I need to get the status code and the coordinates. > > Any help is greatly appreciated. > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060714/f9b16bca/attachment-0001.html
Cuong Tran wrote:> See examples here > http://www.germane-software.com/software/rexml/docs/tutorial.html > > (google is your friend)Thanks for the help! I was able to figure it out with that tutorial and looking at the google-geocode.rb file from the gem. Here''s what I came up with url=''http://maps.google.com/maps/geo?'' address = ''q=1600 Amphitheatre Pkwy, Mountain View, CA'' address1 = URI.escape(address) googleoutput = ''&output=xml'' googlekey = ''&key=mykey'' result=URI(url+address1+googleoutput+googlekey ).read doc = Document.new(result) root = doc.root coordinates = root.elements[''/kml/Response/Placemark/Point/coordinates''].text long, lat, = coordinates.split('','').map { |v| v.to_f } -- Posted via http://www.ruby-forum.com/.