Created
October 11, 2015 16:28
-
-
Save jiunjiun/e2975ccbb5b48efbb510 to your computer and use it in GitHub Desktop.
This file contains 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
# 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