计算地图上两点间的距离,使用的是谷歌地图

  1. <?php
  2. class GeoHelper
  3. {
  4. /**
  5. * @param int $lat1
  6. * @param int $lon1
  7. * @param int $lat2
  8. * @param int $lon2
  9. * @param string $unit
  10. * @return
  11. */
  12. public static function distance($lat1, $lon1, $lat2, $lon2, $unit = "K")
  13. {
  14. $theta = $lon1 - $lon2;
  15. $dist = sin(deg2rad($lat1)) * sin(deg2rad($lat2)) + cos(deg2rad($lat1)) * cos(deg2rad
  16. ($lat2)) * cos(deg2rad($theta));
  17. $dist = acos($dist);
  18. $dist = rad2deg($dist);
  19. $miles = $dist * 60 * 1.1515;
  20. $unit = strtoupper($unit);
  21.  
  22. if ($unit == "K") {
  23. return ($miles * 1.609344);
  24. } else
  25. if ($unit == "N") {
  26. return ($miles * 0.8684);
  27. } else { //mi
  28. return $miles;
  29. }
  30. }
  31.  
  32. /**
  33. *
  34. * @param string $address
  35. * @param string $apikey
  36. * @return array [1]:lat [0]:lng
  37. */
  38. public static function getLatLng($address, $apikey)
  39. {
  40. $find = array("\\n", "\\r", " ");
  41. $replace = array("", "", "+");
  42. $address = str_replace($find, $replace, $address);
  43. $url = 'http://maps.google.com/maps/geo?q=' . $address . '&key=' . $apikey .
  44. '&sensor=false&output=xml&oe=utf8';
  45. $response = self::xml2array($url);
  46. $coordinates = $response['kml']['Response']['Placemark']['Point']['coordinates'];
  47. if (!empty($coordinates)) {
  48. $point_array = split(",", $coordinates);
  49. return $point_array;
  50. }
  51. }
  52. }

计算地图上两点间的距离PHP类的更多相关文章

  1. 利用JS实现的根据经纬度计算地球上两点之间的距离

      最近用到了根据经纬度计算地球表面两点间距离的公式,然后就用JS实现了一下. 计算地球表面两点间的距离大概有两种办法. 第一种是默认地球是一个光滑的球面,然后计算任意两点间的距离,这个距离叫做大圆距 ...

  2. Python计算地图上两点经纬度间的距离

    处理地图数据时,经常需要用到两个地理位置间的距离.比如A点经纬度(110.0123, 23.32435),B点经纬度(129.1344,25.5465),求AB两点之间的距离.我们可以用haversi ...

  3. HDOJ2001计算两点间的距离

    计算两点间的距离 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Su ...

  4. J - 计算两点间的距离

      Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u   Description 输入两 ...

  5. 计算两点间的距离-hdu2001

    Problem Description 输入两点坐标(X1,Y1),(X2,Y2),计算并输出两点间的距离.   Input 输入数据有多组,每组占一行,由4个实数组成,分别表示x1,y1,x2,y2 ...

  6. 计算两点间的距离,hdu-2001

    计算两点间的距离 Problem Description 输入两点坐标(X1,Y1),(X2,Y2),计算并输出两点间的距离.   Input 输入数据有多组,每组占一行,由4个实数组成,分别表示x1 ...

  7. HDU 2001 计算两点间的距离

    http://acm.hdu.edu.cn/showproblem.php?pid=2001 Problem Description 输入两点坐标(X1,Y1),(X2,Y2),计算并输出两点间的距离 ...

  8. hdu2001 计算两点间的距离【C++】

    计算两点间的距离 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Su ...

  9. 杭电ACM2001--计算两点间的距离

    计算两点间的距离 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Su ...

随机推荐

  1. SpringBoot项目从Git拉取代码并完成编译打包启动的sh自动脚本

    操作步骤: 1.进入/home/servers/codes/xxxx-dev/目录,从git上将项目clone下来: 2.确保/usr/local/xxx/xxxx-dev目录存在: 3.确保sh脚本 ...

  2. Python3基础 from...import 局部导入

             Python : 3.7.3          OS : Ubuntu 18.04.2 LTS         IDE : pycharm-community-2019.1.3    ...

  3. flutter upgrade之后出现Attribute application@appComponentFactory value=(android.support.v4.app.CoreComponentFactory) from

    错误信息 Initializing gradle... Resolving dependencies... Running Gradle task 'assembleDebug'... /Users/ ...

  4. MSYS 工具和TOOLCHAIN的配置

    博客转载:https://blog.csdn.net/hunterhuang2013/article/details/70880569 1. MSYS2 自带的开发环境,安装的包叫 msys2-dev ...

  5. java多线程(一)创建线程的四种方式

    1.   什么是并发与并行 要想学习多线程,必须先理解什么是并发与并行 并行:指两个或多个事件在同一时刻发生(同时发生). 并发:指两个或多个事件在同一个时间段内发生. 2.   什么是进程.线程 进 ...

  6. C++ vector使用实例

    C++ vector #include <iostream> #include <vector> #include <string> #include <al ...

  7. MySQL慢查询参数

    开启mysql慢查询日志 修改/etc/mysql/my.cnf配置文件,添加: [mysqld]slow_query_log = onslow_query_log_file = /var/lib/m ...

  8. ABAP基础篇1 内表

    内表类型 abap 内表类型有三种: 标准表(一般ABAP程序中用的最多就是这种表) 系统为该表的每一行数据生成一个逻辑索引,自己内部维护着行号(Index)的编码.表的键值不唯一,且没有按照表键自动 ...

  9. Linux CentOS7 通过 yum 搭建 svn 服务器,并配置权限

    1,使用 yum 安装 svn 服务器 yum -y install subversion rpm -ql subversion -- 改命令可以查看 svn 的安装位置 2,创建仓库根目录,可任意选 ...

  10. Android studio配置国内镜像源

    Android studio配置国内镜像源 不使用镜像也是可以的,据说谷歌在中国搭建了服务器 如果直接使用有问题,不妨使用镜像试试.有自动探测代理配置和手动代理配置. https://blog.csd ...