计算地图上两点间的距离PHP类
<?php class GeoHelper { /** * @param int $lat1 * @param int $lon1 * @param int $lat2 * @param int $lon2 * @param string $unit * @return */ public static function distance($lat1, $lon1, $lat2, $lon2, $unit = "K") { $theta = $lon1 - $lon2; $dist = sin(deg2rad($lat1)) * sin(deg2rad($lat2)) + cos(deg2rad($lat1)) * cos(deg2rad ($lat2)) * cos(deg2rad($theta)); $dist = acos($dist); $dist = rad2deg($dist); $miles = $dist * 60 * 1.1515; $unit = strtoupper($unit); if ($unit == "K") { return ($miles * 1.609344); } else if ($unit == "N") { return ($miles * 0.8684); } else { //mi return $miles; } } /** * * @param string $address * @param string $apikey * @return array [1]:lat [0]:lng */ public static function getLatLng($address, $apikey) { $find = array("\n", "\r", " "); $replace = array("", "", "+"); $address = str_replace($find, $replace, $address); $url = 'http://maps.google.com/maps/geo?q=' . $address . '&key=' . $apikey . '&sensor=false&output=xml&oe=utf8'; $response = self::xml2array($url); $coordinates = $response['kml']['Response']['Placemark']['Point']['coordinates']; if (!empty($coordinates)) { $point_array = split(",", $coordinates); return $point_array; } } }
计算地图上两点间的距离,使用的是谷歌地图
免责声明
本站所有资源均由网友贡献或各大下载网站转载。请自行检查软件的完整性!本站所有资源仅供学习参考。请不要将它们用于商业目的。否则,一切后果由您负责!如有侵权,请联系我们删除。联系方式:admin@php.cn
相关文章

27 Nov 2024
计算 Google 地图 V3 中点之间的距离在 Google 地图 V3 中,可以使用半正弦计算两个标记之间的距离...

29 Nov 2024
使用 Google 地图 V3 确定两点之间的距离计算 Google 地图 V3 中标记之间的距离可以通过以下方式实现...

30 Nov 2024
计算 Google 地图 V3 中两个标记之间的距离确定 Google 地图 V3 中标记所表示的两点之间的距离是...


热工具

热门文章
如何修复KB5055523无法在Windows 11中安装?
10 Apr 2025
故障排查
如何修复KB5055518无法在Windows 10中安装?
10 Apr 2025
故障排查
<🎜>:死铁路 - 如何驯服狼
07 Apr 2025
手游攻略
R.E.P.O.的每个敌人和怪物的力量水平
07 Apr 2025
手游攻略
<🎜>:种植花园 - 完整的突变指南
18 Apr 2025
手游攻略