根據經緯度查詢附近企業 | SQL

--第一種git

SELECT  
    ent_id, ent_name, longitude, latitude,  
    ROUND(  
        6378.138 * 2 * ASIN(  
            SQRT(  
                POW(  
                    SIN(  
                        (  
                            40.042307 * PI() / 180 - latitude * PI() / 180  
                        ) / 2  
                    ),  
                    2  
                ) + COS(40.042307 * PI() / 180) * COS(latitude * PI() / 180) * POW(  
                    SIN(  
                        (  
                            116.317205 * PI() / 180 -   longitude * PI() / 180  
                        ) / 2  
                    ),  
                    2  
                )  
            )  
        ) * 1000  
    ) AS juli  
FROM  
ent  
ORDER BY  
    juli DESC  
limit 0,100;

 

 

--第二種spa

SELECT  
    ent_id, ent_name, longitude, latitude
FROM  
ent
ORDER BY   POWER(MOD(ABS(longitude-116.317205),360),2) + POWER(ABS(latitude-40.042307),2) DESC  
limit 0,100;

 

 

--根據右上角經緯度和左下角經緯度查詢範圍內企業code

select ent_id, ent_name, longitude, latitude
      from ent 
      where #{topRightLatitude,jdbcType=DECIMAL}>latitude and latitude>#{leftLowerLatitude,jdbcType=DECIMAL}
      and #{topRightLongitude,jdbcType=DECIMAL}>longitude and longitude>#{leftLowerLongitude,jdbcType=DECIMAL}
相關文章
相關標籤/搜索