How to get Distance in KM in this query

后端 未结 3 1101
花落未央
花落未央 2021-01-29 14:59
$salons = Salon::select(\'salons.*\')
    ->selectRaw(\'( 6371* acos( cos( radians(?) ) *
                   cos( radians( lat ) )
                   * cos( radians(          


        
3条回答
  •  暖寄归人
    2021-01-29 15:13

    for obtaining the km you should use 111.045 km per degree (as an approximation)

       ( 111.045 * acos( cos( radians(?) ) *
                           cos( radians( lat ) )
                           * cos( radians( lng ) - radians(?)
                           ) + sin( radians(?) ) *
                           sin( radians( lat ) ) )
                         )
    

提交回复
热议问题