时间:2021-07-01 10:21:17 帮助过:22人阅读
$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;
}