[转] PHP计算两个坐标之间的距离, Calculate the Distance Between Two Points in PHP
Calculate the Distance Between Two Points in PHP
There are a lot of applications where it is useful to know the distance between two coordinates. Here, you'll find a PHP function that takes the latitude and longitude of two points and returns the distance between them in both miles and metric units.
You can also use this to find the distance between two addresses by taking advantage of the Google Geotargetting API.
Here's the function:
function get_distance_between_points($latitude1, $longitude1, $latitude2, $longitude2) {
$theta = $longitude1 - $longitude2;
$miles = (sin(deg2rad($latitude1)) * sin(deg2rad($latitude2))) + (cos(deg2rad($latitude1)) * cos(deg2rad($latitude2)) * cos(deg2rad($theta)));
$miles = acos($miles);
$miles = rad2deg($miles);
$miles = $miles * 60 * 1.1515;
$feet = $miles * 5280;
$yards = $feet / 3;
$kilometers = $miles * 1.609344;
$meters = $kilometers * 1000;
return compact('miles','feet','yards','kilometers','meters');
}
调用
And here's an example of the function in action, using two coordinates in New York City:
$point1 = array('lat' => 40.770623, 'long' => -73.964367);
$point2 = array('lat' => 40.758224, 'long' => -73.917404);
$distance = get_distance_between_points($point1['lat'], $point1['long'], $point2['lat'], $point2['long']);
foreach ($distance as $unit => $value) { echo $unit.': '.number_format($value,4).'<br />'; }
The example returns the following:
miles: 2.6025 //英里
feet: 13,741.4350 //英尺
yards: 4,580.4783 //码
kilometers: 4.1884 //公里(km)
meters: 4,188.3894 //米(m)
FROM : https://inkplant.com/code/calculate-the-distance-between-two-points.php
[转] PHP计算两个坐标之间的距离, Calculate the Distance Between Two Points in PHP的更多相关文章
- PHP计算两个坐标之间的距离
<?php /** * 计算两点之间的距离 * @param $lng1 经度1 * @param $lat1 纬度1 * @param $lng2 经度2 * @param $lat2 纬度2 ...
- iOS 计算两个坐标之间的距离
//第一个坐标 CLLocation *before=[[CLLocation alloc] initWithLatitude:29.553968 longitude:106.538872]; //第 ...
- mysql实现经纬度计算两个坐标之间的距离sql语句
select *,(2 * 6378.137* ASIN(SQRT(POW(SIN(PI()*(111.86141967773438-latitude)/360),2)+COS(PI()*33.070 ...
- mysql实现经纬度计算两个坐标之间的距离
DELIMITER $$CREATE DEFINER = CURRENT_USER FUNCTION `getDistance`(`lon1` float,`lat1` float,`lon2` fl ...
- PHP MYSQL 搜索周边坐标,并计算两个点之间的距离
搜索附近地点,例如,坐标(39.91, 116.37)附近500米内的人,首先算出“给定坐标附近500米”这个范围的坐标范围. 虽然它是个圆,但我们可以先求出该圆的外接正方形,然后拿正方形的经纬度范围 ...
- IOS 计算两个经纬度之间的距离
IOS 计算两个经纬度之间的距离 一 丶 -(double)distanceBetweenOrderBy:(double) lat1 :(double) lat2 :(double) lng1 :(d ...
- 高德地图 API 计算两个城市之间的距离
1. 目前在项目中,遇到一个需求不会做,就是要计算两个城市之间的距离,而这两个城市的输入是可变的,如果要使用数据库来先存储两地之间的距离,调用的时候再来调用,那么存数据的时候,要哭的,因为光是省级区域 ...
- 计算两个坐标点的距离(高德or百度)
/// <summary> /// 获取两个坐标之间的距离 /// </summary> /// <param name="lat1">第一个坐 ...
- 计算两个经纬度之间的距离(python算法)
EARTH_REDIUS = 6378.137 def rad(d): return d * pi / 180.0 def getDistance(lat1, lng1, lat2, lng2): r ...
随机推荐
- jQueryUI日期显示
<script type="text/javascript" src="js/My97DatePicker/WdatePicker.js">< ...
- URAL 1303. Minimal Coverage(DP)
题目链接 又是输出路径...这题完全受上题影响,感觉两个题差不多..用了基本上一样的算法写了,这题比较纠结,就是卡内存啊...5000*5000的数组开不了..然后没办法,水了好几次MLE,看了一下虎 ...
- Bootstrap整合ASP.NET MVC验证、jquery.validate.unobtrusive
没什么好讲的,上代码: (function ($) { var defaultOptions = { validClass: 'has-success', errorClass: 'has-error ...
- [CareerCup] 17.8 Contiguous Sequence with Largest Sum 连续子序列之和最大
17.8 You are given an array of integers (both positive and negative). Find the contiguous sequence w ...
- Hadoop_简单操作ZooKeeper
一.概念 1. 一个开源的.分布式的,为分布式应用提供协调服务的Apache项目 2. 提供一个简单的原语集合,以便于分布式应用可以在它之上构建更高层次的同步服务 3. 设计非常易于编程,它使用的是类 ...
- Application中捕获APP中的全局异常
package com.example.administrator.mystudent; import android.app.Application; import android.util.Log ...
- ArcGIS 使用点滴记录
(1)ArcGIS Shapefile数据text类型字段最长为254.若想更长,使用GeoDatabase (2)ArcGIS中出现一些奇奇怪怪的问题,找不到解决方法时,一般考虑是不是空间参考的问题 ...
- Oracle三大经典表连接适用情况
1.1环境准备 1.2 Nested Loops Join 从上面的试验来看,nested loop jion基本上是没有限制的,可以支持所有的运算. 1.3 Hash Join 1.4 Merge ...
- 讨论一下js获取响应中后台传回来的BigInteger类型的数字时,后几位会自动变为0的问题
后台返回的json:{"data":12345678912345678912} 在js中获取该data得到的值为:12345678912345680000 后经过实验发现,只有数字 ...
- SQL语句判断是否为今天或昨天
方法一 select * from AAA where to_char(a,'yyyymmdd') = to_char(sysdate,'yyyymmdd'); select * from AAA w ...