Last active
August 28, 2015 14:46
-
-
Save bsjohnson/87b499a856a7f3d57ac2 to your computer and use it in GitHub Desktop.
Find a random address in the general vicinity of the United States
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
require "geocoder" | |
require "awesome_print" | |
NORTH = 49.3457868 | |
WEST = -124.7844079 | |
EAST = -66.9513812 | |
SOUTH = 24.7433195 | |
def random_lat_long | |
{ :long => rand * (EAST - WEST) + WEST, :lat => rand * (NORTH - SOUTH) + SOUTH } | |
end | |
lat_long = random_lat_long | |
while (address = Geocoder.search("#{lat_long[:lat]},#{lat_long[:long]}")).empty? | |
lat_long = random_lat_long | |
ap "Couldn't find an address. Waiting a second and trying again.", :color => { :string => :red } | |
sleep(1) # If we didn't find an address, wait a second and try again. | |
end | |
ap "Lat, Long:", :color => { :string => :greenish } | |
ap "#{lat_long[:lat]}, #{lat_long[:long]}", :color => { :string => :green } | |
ap "Address:", :color => { :string => :greenish } | |
ap address.first.formatted_address, :color => { :string => :green } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment