/ Published in: Ruby
pass in the loc variable to g_code as a string. It doesn't do any sort of error-checking on the string however.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
require 'net/http' require 'uri' class Gcode def initialize @g_url = "http://maps.google.com/maps/geo?q=" @output = "&output=csv" @key = " [API KEY HERE] " end def g_code(loc) query = @g_url << loc << @output << @key query.to_s response = Net::HTTP.get_response URI.parse(query) fields = response.body.split(',') if fields[0] = 200 latlong = {"x" => fields[2], "y" => fields[3] } return latlong else puts "sorry, address cannot be geocoded" end end end