我需要使用2km半径和当前纬度和经度

时间:2018-05-29 07:47:58

标签: sql oracle

 SELECT id, LATITUDE, LONGITUDE, distance
    FROM
  (
    SELECT a.hosp_seq_id, 
           LATITUDE, LONGITUDE,
           (3959 * ACOS(COS(RADIANS(LATITUDE)) 
                 * COS(RADIANS(mylat)) 
                 * COS(RADIANS(LONGITUDE) - RADIANS(mylng)) 
                 + SIN(RADIANS(LATITUDE)) 
                 * SIN(RADIANS(mylat)) 
               ))
           AS distance,
           b.mydst
      FROM app.tpa_hosp_info a 
      JOIN (
        SELECT 12.561 AS mylat,
               77.48 AS mylng,
               2 AS mydst
          FROM DUAL
      )b ON (1 = 1)
     WHERE LATITUDE >=  mylat -(mydst/69)
       AND LATITUDE <=  mylat +(mydst/69)
       AND LONGITUDE >= mylng -(mydst/(69 * COS(RADIANS(mylat))))
       AND LONGITUDE <= mylng +(mydst/(69 * COS(RADIANS(mylat))))
  )a
   WHERE distance <= mydst
   ORDER BY distance

0 个答案:

没有答案