当前位置:网站首页>经纬度 多点 获取中心点 已解决
经纬度 多点 获取中心点 已解决
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 版本均有
边栏推荐
- containerd客户端比较
- Freertos+stm32l+esp8266+mqtt protocol transmits temperature and humidity data to Tencent cloud IOT platform
- 智慧家——全家具功能
- C another new class is ICO? And app Use of config
- 模板引擎——FreeMarker初体验
- Digital circuit - adder
- 制作3D浪漫炫酷相册【附源码】
- Unified gateway
- Download and install flume
- react + router 框架下的路由跳转后缓存页面存初始参数
猜你喜欢

. Net using access 2010 database

Motor monitoring system based on MCGS and stm32

RT-Thread 项目工程搭建和配置--(Env Kconfig)

Msp430f5529lp official board (red) can not debug the problem

关于HC-12无线射频模块使用

Idea configuration

Endnote IEEE TRANSACTIONS ON INDUSTRIAL ELECTRONICS/TIE/TPEL 参考文献格式模板

DGUS新升级:全面支持数字视频播放功能

数字电路——加法器

New library launched | cnopendata China new house information data
随机推荐
Sword finger offer II 096 String interleaving
jarvisoj_ level2_ x64
信息收集的利器,Google骇客语法
Multiple interface calls, using promise all、Promise. Race and promise any
Final review [machine learning]
如何有效地推廣產品
Endnote IEEE TRANSACTIONS ON INDUSTRIAL ELECTRONICS/TIE/TPEL 参考文献格式模板
containerd客户端比较
Flex & Bison 开始
FIFO code implemented in C language
FPGA notes -- implementation of FPGA floating point operation
Is it safe to open a fund account? Are there any risks?
STM32 uses SPI mode to drive TFT-LCD optimization code of hx8347 scheme
C # operate with MySQL
Cartoon shader
网上开通证券账户安全吗 证券网上开户
Redis的安装及启动
sqlserver 区分字符串中字母大小写
QT cmake pure C code calls the system console to input scanf and Chinese output garbled code
填鸭数据即时收集解决方案资源