时间:2021-07-01 10:21:17 帮助过:1人阅读
$sql = "select id,xpoint,ypoint, deal_cate_id,ratio from ".DB_PREFIX."supplier_location where ".$where;
foreach($info as $k=>$v){ $info[$k]['Distance'] =intval(GetDistance($ypoint,$xpoint,$v['ypoint'],$v['xpoint'])*1000);}
// 本函数为获取两坐标之间的距离 // a纬度 a经度 b纬度 b经度 function GetDistance($lat1, $lng1, $lat2, $lng2) { $EARTH_RADIUS = 6378.137; $radLat1 = rad($lat1); $radLat2 = rad($lat2); $a = $radLat1 - $radLat2; $b = rad($lng1) - rad($lng2); $s = 2 * asin(sqrt(pow(sin($a/2),2) + cos($radLat1)*cos($radLat2)*pow(sin($b/2),2))); $s = $s * $EARTH_RADIUS; $s = round($s * 10000) / 10000; return $s;}
排序
order by abs(xpoint-$xpoint), abs(ypoint-$ypoint)
即按两点经纬度差的绝对值进行排序
查的结果后再行计算
或直接将算式 2 * asin(sqrt(pow(sin($a/2),2) + cos($radLat1)*cos($radLat2)*pow(sin($b/2),2)))
放到 sql 语句中,涉及的函数 mysql 都有
度化弧是 RADIANS
排序
order by abs(xpoint-$xpoint), abs(ypoint-$ypoint)
即按两点经纬度差的绝对值进行排序
查的结果后再行计算
或直接将算式 2 * asin(sqrt(pow(sin($a/2),2) + cos($radLat1)*cos($radLat2)*pow(sin($b/2),2)))
放到 sql 语句中,涉及的函数 mysql 都有
度化弧是 RADIANS