Skip to content

Instantly share code, notes, and snippets.

@jiunjiun
Created October 11, 2015 16:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jiunjiun/e2975ccbb5b48efbb510 to your computer and use it in GitHub Desktop.
Save jiunjiun/e2975ccbb5b48efbb510 to your computer and use it in GitHub Desktop.
# coding: utf-8
require 'json'
require 'open-uri'
require 'cgi'
class Geocoder
# GOOGLE_KEY = 'your_google_key' # Google Maps Geocoding API
# GoogleGeocodeUrl = "https://maps.googleapis.com/maps/api/geocode/json?key=#{GOOGLE_KEY}&address="
GoogleGeocodeUrl = "https://maps.googleapis.com/maps/api/geocode/json?address="
def self.geo_info(address)
address = CGI::escape(address).gsub("+", "%20")
url = "#{GoogleGeocodeUrl}#{address}"
results = JSON.parse(open(url).read)
status = results['status']
results = results['results'].first
end
end
geo_info = Geocoder.geo_info("台北101")
p geo_info
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment