当前位置:网站首页>经纬度 多点 获取中心点 已解决
经纬度 多点 获取中心点 已解决
2022-06-25 23:36:00 【PHP代码】
在日常项目中,需要获取多个经纬度 进行 中心点返回。
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));
}
测试结果
// 测试数据
$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 )参考网址
参考: https://stackoverflow.com/questions/6671183/calculate-the-center-point-of-multiple-latitude-longitude-coordinate-pairs
Python Java C# JavaScript Objective-C PHP 版本均有
边栏推荐
- 卡通shader
- QT cmake pure C code calls the system console to input scanf and Chinese output garbled code
- ciscn_ 2019_ en_ two
- Multiple interface calls, using promise all、Promise. Race and promise any
- Inheritance -- holy grail mode
- From query database performance optimization to redis cache - talk about cache penetration, avalanche and breakdown
- 多接口调用,使用Promise.all、Promise.race和Promise.any
- 如何有效地推廣產品
- Is it safe to open a fund account? Are there any risks?
- Music spectrum display toy -- implementation and application of FFT in stm32
猜你喜欢

I2C protocol

100ask seven day IOT training camp learning notes - bare metal program framework design

从查询数据库性能优化谈到redis缓存-谈一谈缓存的穿透、雪崩、击穿

Download and install flume

Online gadget sharing (updated from time to time, current quantity: 2)

STM32 uses SPI mode to drive TFT-LCD optimization code of hx8347 scheme

Web information collection, naked runners on the Internet

Anaconda beginner's notes

Implementation notes of least square fitting conic in stm32

From query database performance optimization to redis cache - talk about cache penetration, avalanche and breakdown
随机推荐
ciscn_ 2019_ en_ two
JS reverse case: cracking login password
From query database performance optimization to redis cache - talk about cache penetration, avalanche and breakdown
STM32 uses SPI mode to drive TFT-LCD optimization code of hx8347 scheme
Classic interview questions: mouse drug test and Hamming code
Motor monitoring system based on MCGS and stm32
数组中的第K个最大元素
FPGA notes -- implementation of FPGA floating point operation
Recognize map
MySQL custom function instance
What training brings happiness
2022资料员-通用基础(资料员)考试模拟100题及在线模拟考试
Comment promouvoir efficacement les produits
QT cmake pure C code calls the system console to input scanf and Chinese output garbled code
Unified gateway
Design and process analysis of anti backflow circuit for MOS transistor
Flex & Bison 开始
Download and install flume
Dgus new upgrade: fully support digital video playback function
Nacos注册中心