当前位置:网站首页>Longitude and latitude multipoint acquisition center point has been solved
Longitude and latitude multipoint acquisition center point has been solved
2022-06-26 01:22:00 【PHP code】
In everyday projects , You need to obtain multiple longitudes and latitudes Conduct Center point return .
function GetCenterFromDegrees($data){
if (!is_array($data)) return FALSE;
$num_coords = count($data);
$X = 0.0;
$Y = 0.0;
$Z = 0.0;
foreach ($data as $coord){
$lat = deg2rad((float)$coord[0]);
$lon = deg2rad((float)$coord[1]);
$a = cos($lat) * cos($lon);
$b = cos($lat) * sin($lon);
$c = sin($lat);
$X += $a;
$Y += $b;
$Z += $c;
}
$X /= $num_coords;
$Y /= $num_coords;
$Z /= $num_coords;
$lon = atan2($Y, $X);
$hyp = sqrt($X * $X + $Y * $Y);
$lat = atan2($Z, $hyp);
return array(rad2deg($lat), rad2deg($lon));
}
test result
// Test data
$data = array(
array(45.849382, 76.322333),
array(45.843543, 75.324143),
array(45.765744, 76.543223),
array(45.784234, 74.542335)
);
print_r(GetCenterFromDegrees($data));
// Array ( [0] => 45.813538469271 [1] => 75.682996448603 )
Refer to the website
Reference resources : https://stackoverflow.com/questions/6671183/calculate-the-center-point-of-multiple-latitude-longitude-coordinate-pairs
Python Java C# JavaScript Objective-C PHP All versions have
边栏推荐
- C#使用MySql进行操作
- [Excel知识技能] Excel数据类型
- Establish a j-link GDB cross debugging environment for Px4
- When you run the demo using the gin framework, there is an error "listen TCP: 8080: bind: an attempt was made to access a socket in a way forbidden"
- I2C protocol
- vite打包构建时 @charset utf-8警告问题处理;
- 走 迷 宫
- New library launched | cnopendata wholesale price data of agricultural products
- 如何有效地推廣產品
- QT cmake pure C code calls the system console to input scanf and Chinese output garbled code
猜你喜欢
随机推荐
containerd客户端比较
Sqlserver is case sensitive
100ask seven day IOT training camp learning notes - bare metal program framework design
Installation and startup of redis
C#使用MySql进行操作
Flex & bison start
Etcd database source code analysis cluster communication initialization
Modelsim simulation FFT core cannot be simulated solution (qsys)
C another new class is ICO? And app Use of config
关于HC-12无线射频模块使用
走 迷 宫
Web information collection, naked runners on the Internet
信息收集的利器,Google骇客语法
STM32GPIO
FIFO code implemented in C language
Essence and thoughts of 30 lectures on product thinking
2022年育婴员(五级)考试试题及答案
Zhihuijia - full furniture function
Px4 system terminal for pixhawk
Dgus new upgrade: fully support digital video playback function