Created
October 5, 2012 17:14
-
-
Save choipd/3841074 to your computer and use it in GitHub Desktop.
call_geocoding 구현
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
api_key = "당신의 다음 Open API 키" | |
def call_geocoding(address) | |
begin | |
uri = "http://apis.daum.net/local/geo/addr2coord?apikey=#{api_key}&output=xml&q=#{URI::encode(address)}" | |
doc = Nokogiri::XML(open(uri)) | |
rescue OpenURI::HTTPError => the_error | |
the_status = the_error.io.status[0] | |
puts "[#{the_status}]" | |
else | |
if doc.xpath("//lng[1]").text == "" then | |
puts "#{address} failed!" | |
return call_geocoding(address.gsub(/\s.*$/, "")) | |
end | |
return doc | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment