首页 > 数据库技术 > 详细

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

时间:2017-08-18 21:04:07      阅读:425      评论:0      收藏:0      [点我收藏+]

--第一种

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

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!