Permalink
Browse files

ok

  • Loading branch information...
1 parent 3b829d9 commit 83da7581532d4f7bb1ebbb7bc9c79495b8cf7d93 @yupbank committed Feb 28, 2012
Showing with 10 additions and 6 deletions.
  1. BIN rest.db
  2. +4 −2 rest/utils.py
  3. +6 −4 rest/views.py
View
BIN rest.db
Binary file not shown.
View
@@ -20,8 +20,10 @@ def get_distance_hav_by_lat_lng(lat0, lng0, lat1, lng1):
def get_lat_lng_range(lat0, lng0, distance=1.0):
lat0, lng0 = map(float, [lat0, lng0])
- dlng = 2 * asin(sin(distance / (2 * EARTH_RADIUS)) / cos(lat0))
- dlng = degrees(dlng)
+
+ dlng = distance/(30.887*cos(lat0))
+ #dlng = 2 * asin(sin(distance / (2 * EARTH_RADIUS)) / cos(lat0))
+ #dlng = degrees(dlng)
dlat = distance / EARTH_RADIUS
dlat = degrees(dlat)
View
@@ -12,7 +12,7 @@ def index(request):
def places(request):
lat = request.GET.get('lat', None)
lng = request.GET.get('lng', None)
- limit = request.GET.get('limit', 0)
+ limit = request.GET.get('limit', 10)
offset = request.GET.get('offset', 0)
radius = request.GET.get('radius', 1)
data = []
@@ -24,11 +24,13 @@ def places(request):
try:
limit, offset = map(int,[limit, offset])
- lat, lng = map(float,[lat, lng])
+ lat, lng = map(float,[lat, lng])
radius = float(radius)
except Exception,e:
limit, offset = 10, 0
error.append(e.message)
+ if filter(lambda x:abs(x[0])>90 or abs(x[1])>180,[[lat,lng]]):
+ error.append('lat or lng wrong!')
@@ -42,8 +44,7 @@ def places(request):
)
lat1, lat2, lng1, lng2 = get_lat_lng_range(lat, lng, radius)
- places = Place.objects.filter(lat__gt=lat1).filter(lat__lt=lat2).filter(lng__gt=lng2).filter(lng__lt=lng1)
-
+ places = Place.objects.filter(lat__gt=lat1).filter(lat__lt=lat2).filter(lng__gt=lng1).filter(lng__lt=lng2)
if places:
for p in places:
@@ -56,6 +57,7 @@ def places(request):
distance = get_distance_hav_by_lat_lng(p.lat,p.lng,lat,lng)
)
data.append(result)
+ print data
else:
error.append('out of range')

0 comments on commit 83da758

Please sign in to comment.