Created
October 30, 2018 19:57
-
-
Save CheezItMan/122a33300d0a7984bd9e166d66d59651 to your computer and use it in GitHub Desktop.
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
require 'httparty' | |
require 'awesome_print' | |
KEY = "AIzaSyBP30mYnbwKpZ0lCHtp6FuvcNSjNG0GsGM" | |
PLACE_FROM_TEXT_STRING = "https://maps.googleapis.com/maps/api/place/findplacefromtext/json?inputtype=textquery" | |
DETAIL_STRING = "https://maps.googleapis.com/maps/api/place/details/json" | |
#Starter Code: | |
seven_wonders = ["Great Pyramid of Giza", "The Ishtar Gate", "Colossus of Rhodes", "Pharos of Alexandria", "Statue of Zeus at Olympia", "Temple of Artemis", "Mausoleum at Halicarnassus"] | |
output = {} | |
seven_wonders.each do |wonder| | |
full_uri = "#{PLACE_FROM_TEXT_STRING}&key=#{KEY}&input=#{wonder}" | |
parsed_response = HTTParty.get(full_uri).parsed_response | |
place_id = parsed_response["candidates"][0]["place_id"] | |
full_uri = "#{DETAIL_STRING}?key=#{KEY}&placeid=#{place_id}" | |
parsed_response = HTTParty.get(full_uri).parsed_response | |
output[wonder] = { | |
lat: { | |
lng: parsed_response["result"]["geometry"]["location"]["lng"], | |
lat: parsed_response["result"]["geometry"]["location"]["lat"] | |
} | |
} | |
end | |
ap output | |
#Example Output: | |
#{"Great Pyramind of Giza"=>{"lat"=>29.9792345, "lng"=>31.1342019}, "Hanging Gardens of Babylon"=>{"lat"=>32.5422374, "lng"=>44.42103609999999}, "Colossus of Rhodes"=>{"lat"=>36.45106560000001, "lng"=>28.2258333}, "Pharos of Alexandria"=>{"lat"=>38.7904054, "lng"=>-77.040581}, "Statue of Zeus at Olympia"=>{"lat"=>37.6379375, "lng"=>21.6302601}, "Temple of Artemis"=>{"lat"=>37.9498715, "lng"=>27.3633807}, "Mausoleum at Halicarnassus"=>{"lat"=>37.038132, "lng"=>27.4243849}} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment