Skip to content

Instantly share code, notes, and snippets.

@zodman
Created September 21, 2012 17:16
Show Gist options
  • Save zodman/3762723 to your computer and use it in GitHub Desktop.
Save zodman/3762723 to your computer and use it in GitHub Desktop.
Calc the near lat,lng in radius
import random
def get_near_point( lat,lng, radius):
""" http://gis.stackexchange.com/questions/25877/how-to-generate-random-locations-nearby-my-location"""
import math
u = random.random()
v = random.random()
r_d = radius/111300.0
t = 2* math.pi*v
w = r_d * math.sqrt(u)
x = w* math.cos(t)
y = w*math.sin(t)
newx = x/math.cos(float(lat))
return ( y+ float(lat), newx + float(lng))
print get_near_point(21.030093, -89.558248, 100)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment