码迷,mamicode.com
首页 > 数据库 > 详细

根据经纬度查询附近企业 | SQL

时间:2017-08-18 21:30:44      阅读:271      评论:0      收藏:0      [点我收藏+]

标签:--   经纬度   bsp   esc   log   des   from   企业   desc   

--第一种

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;

 

 

--第二种

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;

 

 

--根据右上角经纬度和左下角经纬度查询范围内企业

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}

 

根据经纬度查询附近企业 | SQL

标签:--   经纬度   bsp   esc   log   des   from   企业   desc   

原文地址:http://www.cnblogs.com/hezhao/p/7392090.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!