Skip to content

Instantly share code, notes, and snippets.

@oojikoo-gist
Created October 14, 2015 19:26
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oojikoo-gist/c4cba089203f6ce3f351 to your computer and use it in GitHub Desktop.
Save oojikoo-gist/c4cba089203f6ce3f351 to your computer and use it in GitHub Desktop.
ruby: random_location_circle
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