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.