本文主要是介绍根据经纬度,距离,角度计算另外一个点,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
以下距离单位KM
/*** @static getLonLat.** @param $lon* @param $lat* @param $distance* @param $angle** @return string*/public static function getLonLat1($lon, $lat, $distance, $angle){$ea = 6378137; // 赤道半径$eb = 6356725; // 极半径$dx = $distance * 1000 * sin($angle * pi() / 180);$dy = $distance * 1000 * cos($angle * pi() / 180);$ec = $eb + ($ea - $eb) * (90 - $lat) / 90;$ed = $ec * cos($lat * pi() / 180);$lon = ($dx / $ed + $lon * pi() / 180) * 180 / pi();$lat = ($dy / $ec + $lat * pi() / 180) * 180 / pi();return $lon . ' ' . $lat;}/*** @static getLonLat.** @param $lon* @param $lat* @param $distance* @param $angle** @return float|int|string*/public static function getLonLat2($lon, $lat, $distance, $angle){// latlngA . longitude + (distance * Math . sin(angle * Math . PI / 180)) / (111 * Math . cos(latlngA . latitude * Math . PI / 180)// latlngA . latitude + (distance * Math . cos(angle * Math . PI / 180)) / 111$lat = $lat + ($distance * cos($angle * pi() / 180)) / 111;$lon = $lon + ($distance * sin($angle * pi() / 180)) / (111 * cos($lat * pi() / 180));return $lon . ' ' . $lat;}/*** @static getLonLat.** @param $lng* @param $lat* @param $distance* @param $angle** @return array*/public static function getLonLat($lng, $lat, $distance, $angle){# 地球半径 KM$raidus = 6378.137;$pi = 3.14;$latitude1 = $lat * ($pi / 180);$longitude1 = $lng * ($pi / 180);$brng = $angle * ($pi / 180);$latitude2 = asin(sin($latitude1) * cos($distance / $raidus) + cos($latitude1) * sin($distance / $raidus) * cos($brng));$longitude2 = $longitude1 + atan2(sin($brng) * sin($distance / $raidus) * cos($latitude1), cos($distance / $raidus) - sin($latitude1) * sin($latitude2));$latitude2 = $latitude2 * (180 / $pi);$longitude2 = $longitude2 * (180 / $pi);$lat2 = round($latitude2, 6);$lng2 = round($longitude2, 6);return ['lat' => $lat2, 'lng' => $lng2];}
这篇关于根据经纬度,距离,角度计算另外一个点的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!