Commits

Anonymous committed 8634fc3

modify distance formula

Comments (0)

Files changed (1)

         return json.dumps(temp)
 
 class searchMall(object):
-    def POST(self):
+    def GET(self):
         i = web.input(keyword=None, city=None, state=None, latitude=None, longitude=None, distance=None, page=1, pageSize=20)
         try:
             page = int(i.page)
             pageSize = int(i.pageSize)
         except:
             pageSize = 20
-        web.header('Content-Type', 'application/json')
+        #web.header('Content-Type', 'application/json')
         temp = []
         sql = 'SELECT m.id AS mallId, m.name AS mallName ' \
             'FROM malls m ' \
         elif i.city and (i.keyword or i.state):
             sql = sql + 'AND m.cityId = %s ' % i.city
         if i.latitude and i.longitude and i.distance and (not i.keyword) and (not i.state) and (not i.city):
-            sql = sql + 'ACOS((COS(%s)*COS(m.latitude)*COS(%s)*COS(m.longitude) + COS(%s)*SIN(%s)*COS(m.latitude)*SIN(m.longitude)))*6378*1000 <= %s ' % (i.latitude, i.longitude, i.latitude, i.longitude, i.distance)
+            sql = sql + 'ACOS(COS(RADIANS(%s))*COS(RADIANS(m.latitude))*COS(RADIANS(m.longitude) - RADIANS(%s)) + SIN(RADIANS(%s))*SIN(RADIANS(m.latitude)))*1000 <= %s ' % (i.latitude, i.longitude, i.latitude, i.distance)
         elif i.latitude and i.longitude and i.distance and (i.keyword or i.state or i.city):
-            sql = sql + 'AND ACOS((COS(%s)*COS(m.latitude)*COS(%s)*COS(m.longitude) + COS(%s)*SIN(%s)*COS(m.latitude)*SIN(m.longitude)))*6378*1000 <= %s ' % (i.latitude, i.longitude, i.latitude, i.longitude, i.distance)
+            sql = sql + 'AND ACOS(COS(RADIANS(%s))*COS(RADIANS(m.latitude))*COS(RADIANS(m.longitude) - RADIANS(%s)) + SIN(RADIANS(%s))*SIN(RADIANS(m.latitude)))*1000 <= %s ' % (i.latitude, i.longitude, i.latitude, i.distance)
         if not i.keyword and not i.state and not i.state and not i.city and not i.latitude and not i.longitude and not i.distance:
             return json.dumps([])
         sql = sql + 'GROUP BY m.id ORDER BY m.name ASC LIMIT %d, %d' % ((page-1)*pageSize, pageSize)