code: def find_n_nearest(self, lat, lng, n=5, radius=None):
          
          engine, t_point = self.engine, self.t_point
          if radius:
              # Use a simple box filter to minimize candidates
              # Define latitude longitude boundary
              dist_btwn_lat_deg = 69.172
              dist_btwn_lon_deg = cos(lat) * 69.172
              lat_degr_rad = abs(radius * 1.05 / dist_btwn_lat_deg)
              lon_degr_rad = abs(radius * 1.05 / dist_btwn_lon_deg)
  
              lat_lower = lat - lat_degr_rad
              lat_upper = lat + lat_degr_rad
              lng_lower = lng - lon_degr_rad
              lng_upper = lng + lon_degr_rad
  
              filters = [
                  t_point.c.lat >= lat_lower,
                  t_point.c.lat <= lat_upper,
                  t_point.c.lat >= lng_lower,
                  t_point.c.lat >= lng_upper,
              ]
          else:
              radius = 999999.9
              filters = []
  
          s = select([t_point]).where(and_(*filters))
  
          heap = list()
          for row in engine.execute(s):
              dist = great_circle((lat, lng), (row.lat, row.lng))
              if dist <= radius:
                  heap.append((dist, row.data))
  
          # Use heap sort to find top-K nearest
          n_nearest = heapq.nsmallest(n, heap, key=lambda x: x[0])
          return n_nearest
docs: Find n nearest point within certain distance from a point.
  
          :param lat: latitude of center point.
          :param lng: longitude of center point.
          :param n: max number of record to return.
          :param radius: only search point within ``radius`` distance.
  
          **中文文档**