찾다

 >  Q&A  >  본문

java - sql计算离哪里的距离问题。

手机端传个经纬度 想要查询到指定商家的距离

sql:String sql = "SELECT c.pubid,c.couponname couponName,c.type,c.couponfee / 100 couponfee,c.pic1_path picPath,count(c.fetch_num) AS num,g.category_name categoryName,"; 
        sql += " IF(ISNULL(r.minfee) || LENGTH(trim(r.minfee))<1,r.maxfee,r.minfee) fee,sc.id shopCartId,";
        sql += " ifnull((SELECT min(round(6378.138 * 2 * asin(sqrt(pow(sin(("+positionNS+" * pi() / 180 - s.positionNS * pi() / 180) / 2),2) + cos("+positionNS+" * pi() / 180) * cos(s.positionNS * pi() / 180) ";
        sql += " * pow(sin(("+positionWE+"* pi() / 180 - s.positionWE * pi() / 180) / 2),2))),2)) AS distance";
        sql += " FROM market s,saas m WHERE s.saas = m.id AND s.saas = ru.saas ) ,0) distance";
        sql += " FROM couponpublish c,hh_coupons_category g,ruledescribe r,actionrule ru, shop_cart sc";
        sql += " where c.category_id = g.id and c.getruleid=r.ruleid    and r.actionfile=ru.actionfile    and sc.pub_id = c.pubid    and sc.user_id = '"+userId+"'";
        sql += " GROUP BY c.pubid ORDER BY sc.create_time DESC";
        
         List<Map> list=super.findListbySqlReturnMap(sql);

s.positionWE positionNS是经纬度,想问问怎么个思路写的,这是别人写的给我研究研究。

PHPzPHPz2887일 전317

모든 응답(1)나는 대답할 것이다

  • 天蓬老师

    天蓬老师2017-04-17 17:32:51

    경도와 위도로 거리를 계산하는 공식이 있습니다. 이 쿼리는 해당 공식을 적용하여 작성되었습니다.

    계산식은
    http://www.cnblogs.com/ycsfwhh/archive/2010/12/20/1911232.html

    을 참조하세요.

    회신하다
    0
  • 취소회신하다