Created
October 14, 2015 19:26
-
-
Save oojikoo-gist/c4cba089203f6ce3f351 to your computer and use it in GitHub Desktop.
ruby: random_location_circle
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
def random_location_from(center_lat, center_lng, distance) | |
radius = distance | |
radiusInDegrees=radius/111000.to_f | |
r = radiusInDegrees | |
origin_x = center_lat | |
origin_y = center_lng | |
u = rand(0.00..1.00) | |
v = rand(0.00..1.00) | |
w = r * Math::sqrt(u) | |
t = 2 * Math::PI * v | |
x = w * Math::cos(t) | |
y = w * Math::sin(t) | |
lat = x + origin_x | |
lng = y + origin_y | |
location = [lat, lng] | |
puts "#{location[0]}, #{location[1]}" | |
location = [lat, lng] | |
end | |
#33.367540, 126.538781 | |
puts random_location_from(33.367540,126.538781, 1000) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment