Skip to content

Instantly share code, notes, and snippets.

@leekiernan
Created September 2, 2014 12:20
Show Gist options
  • Save leekiernan/ea5a845020010a6a5dbb to your computer and use it in GitHub Desktop.
Save leekiernan/ea5a845020010a6a5dbb to your computer and use it in GitHub Desktop.
clubs_travel.rb
require 'google_directions'
clubs = {
chelsea: { latitude:51.4816, longitude:-0.191034, directions: {} },
swansea_city: { latitude:51.6428, longitude:-3.93473, directions: {} },
aston_villa: { latitude:52.5092, longitude:-1.88508, directions: {} },
manchester_city: { latitude:53.483, longitude:-2.20024, directions: {} },
liverpool: { latitude:53.4308, longitude:-2.96096, directions: {} },
tottenham_hotspur: { latitude:51.6033, longitude:-0.065684, directions: {} },
arsenal: { latitude:51.5549, longitude:-0.108436, directions: {} },
southampton: { latitude:50.9058, longitude:-1.39114, directions: {} },
hull_city: { latitude:53.7465, longitude:-0.368009, directions: {} },
stoke_city: { latitude:52.9884, longitude:-2.17542, directions: {} },
west_ham: { latitude:51.5321, longitude:0.039225, directions: {} },
queens_park_rangers: { latitude:51.5093, longitude:-0.232204, directions: {} },
sunderland: { latitude:54.9146, longitude:-1.38837, directions: {} },
manchester_united: { latitude:53.4631, longitude:-2.29139, directions: {} },
leicester_city: { latitude:52.6203, longitude:-1.14217, directions: {} },
newcastle_united: { latitude:54.9756, longitude:-1.62179, directions: {} },
everton: { latitude:53.4387, longitude:-2.96619, directions: {} },
west_bromwich_albion: { latitude:52.509, longitude:-1.96418, directions: {} },
crystal_palace: { latitude:51.3983, longitude:-0.085455, directions: {} },
burnley: { latitude:53.7888, longitude:-2.23018, directions: {} }
}
def location_from_club(clubs, club)
"#{clubs[club][:latitude]}, #{clubs[club][:longitude]}"
end
clubs.each do |club, locale|
location = location_from_club(clubs, club)
clubs.each do |cl, locs|
# If route already looked up from other direction.
next if club == cl
dirs = GoogleDirections.new location, location_from_club(clubs, cl)
p dirs.distance_in_miles
p dirs.drive_time_in_minutes
data = {
cl => {
miles: "#{dirs.distance_in_miles}",
minutes: "#{dirs.drive_time_in_minutes}"
}
}
locale[:directions].merge!( data )
p locale
sleep(5)
end
end
# clubs.each do |club,data|
# data[:directions].reject! { |k| k == club }
# end;0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment