当前位置:网站首页>php根据两点经纬度计算距离
php根据两点经纬度计算距离
2022-08-03 19:37:00 【木子李0531】
<?php
$lng1 = 117.11596;
$lat1 = 36.701615;
$lng2 = 117.134968;
$lat2 = 36.692355;
$EARTH_RADIUS = 6378137; //地球半径
$RAD = pi() / 180.0;
$radLat1 = $lat1 * $RAD;
$radLat2 = $lat2 * $RAD;
$latDif = $radLat1 - $radLat2;//纬度差
$lngDif = ($lng1 - $lng2) * $RAD;//经度差
$s = 2 * asin(sqrt(pow(sin($latDif / 2), 2) + cos($radLat1) * cos($radLat2) * pow(sin($lngDif / 2), 2)));
$s = $s * $EARTH_RADIUS;
$s = round($s * 10000) / 10000;
$distance_str = sprintf('%.2f',($s/1000)).'km';
echo $distance_str;
边栏推荐
猜你喜欢
随机推荐
CS kill-free pose
FreeRTOS Intermediate
ERROR: You don‘t have the SNMP perl module installed.
Interview Blitz: What Are Sticky Packs and Half Packs?How to deal with it?
Postgresql source code (65) analysis of the working principle of the new snapshot system Globalvis
阿里二面:多线程间的通信方式有几种?举例说明
【STM32】标准库-自定义BootLoader
图像超分——Real-ESRGAN快速上手
net-snmp编译报错:/usr/bin/ld: cannot find crti.o: No such file or directory
分享即时通讯开发之WebSocket:概念、原理、易错常识、动手实践
【leetcode】剑指 Offer II 008. 和大于等于 target 的最短子数组(滑动窗口,双指针)
【木马免杀】
Postgresql snapshot optimization Globalvis new system analysis (performance greatly enhanced)
MVC vs MVP
epoll + 线程池 + 前后置服务器分离
Calculation of the array serial number of Likou brush questions (one question per day 7/28)
力扣刷题之求两数之和
盘点在线帮助中心对企业能够起到的作用
【leetcode】剑指 Offer II 009. 乘积小于 K 的子数组(滑动窗口、双指针)
Power button brush the topic of merging two orderly array