PHP查询附近的人及其距离的实现方法
1、附近的人
//获取该点周围的4个点
$distance = 1;//范围(单位千米)
$lat = 113.873643;
$lng = 22.573969;
define('EARTH_RADIUS', 6371);//地球半径,平均半径为6371km
$dlng = 2 * asin(sin($distance / (2 * EARTH_RADIUS)) / cos(deg2rad($lat)));
$dlng = rad2deg($dlng);
$dlat = $distance/EARTH_RADIUS;
$dlat = rad2deg($dlat);
$squares = array('left-top'=>array('lat'=>$lat + $dlat,'lng'=>$lng-$dlng),
'right-top'=>array('lat'=>$lat + $dlat, 'lng'=>$lng + $dlng),
'left-bottom'=>array('lat'=>$lat - $dlat, 'lng'=>$lng - $dlng),
'right-bottom'=>array('lat'=>$lat - $dlat, 'lng'=>$lng + $dlng)
);
print_r($squares['left-top']['lat']);
//从数库查询匹配的记录
$info_sql = "select * from `A` where lat<>0 and lat>{$squares['right-bottom']['lat']} and lat<{$squares['left-top']['lat']} and lng>{$squares['left-top']['lng']} and lng<{$squares['right-bottom']['lng']} ";
2、两点之间的距离
function getDistanceBetweenPointsNew($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');
}
$point1 = array('lat' => 40.770623, 'long' => -73.964367);
$point2 = array('lat' => 40.758224, 'long' => -73.917404);
$distance = getDistanceBetweenPointsNew($point1['lat'], $point1['long'], $point2['lat'], $point2['long']);
foreach ($distance as $unit => $value) {
echo $unit.': '.number_format($value,4).'<br />';
}
转“https://www.php.cn/php-weizijiaocheng-316.html”
PHP查询附近的人及其距离的实现方法的更多相关文章
- 使用ElasticSearch完成百万级数据查询附近的人功能
上一篇文章介绍了ElasticSearch使用Repository和ElasticSearchTemplate完成构建复杂查询条件,简单介绍了ElasticSearch使用地理位置的功能. 这一篇我们 ...
- 使用 Redis 如何实现查询附近的人?「视频版」——面试突击 003 期
面试问题 Redis 如何实现查询附近的人? 涉及知识点 Redis 中如何操作位置信息? GEO 底层是如何实现的? 如何在程序实现查询附近的人? 在实际使用中需要注意哪些问题? 视频答案 视频地址 ...
- mongoDB 查询附近的人的语句
mongoDB 自带LBS查询附近的人 {"location":{ $nearSphere: { $geometry: { type : "Point", co ...
- 【百度地图API】如何根据摩卡托坐标进行POI查询,和计算两点距离
原文:[百度地图API]如何根据摩卡托坐标进行POI查询,和计算两点距离 摘要: 百度地图API有两种坐标系,一种是百度经纬度,一种是摩卡托坐标系.在本章你将学会: 1.如何相互转换这两种坐标: 2. ...
- sql查询当前登陆人所管理的校区下的人员
StringBuilder sql = new StringBuilder("select accountId, concat( ',', GROUP_CONCAT(FIND_IN_SET( ...
- [LeetCode] 849. Maximize Distance to Closest Person 最大化最近人的距离
In a row of seats, 1 represents a person sitting in that seat, and 0 represents that the seat is emp ...
- SQL Server中查询用户的对象权限和角色的方法
--SQL Server中查询用户的对象权限和角色的方法 -- 查询用户的object权限 exec sp_helprotect NULL, 'sa' -- 查询用户拥有的role exec sp_h ...
- php使用mysql_query查询超大结果集超内存的解决方法
再使用mysql_query查询超大结果集的时候会出现超出内存限制的致命错误,这是因为mysql_query采用的是查询全部结果然后把结果集全部缓存到内存中的方式. mysql的查询还提供了另外一种查 ...
- SQL 2005 中查询或执行另外的数据库操作的方法
原文:SQL 2005 中查询或执行另外的数据库操作的方法 摘要: 如果,你想在一台数据库服务器上,查询另一个台数据服务器的数据该如何做呢?如果,你想在同一台数据服务器上,在不同的数据库之间查询数据, ...
随机推荐
- 搭建Dubbo Admin(五)
Dubbo Admin下载地址(2019年9月8日):https://github.com/apache/dubbo-admin 注意:JDK要求1.8以上 1. 进入到模块 dubbo-admin- ...
- NOIP 2003 神经网络
洛谷 P1038 神经网络 https://www.luogu.org/problemnew/show/P1038 JDOJ 1278: [NOIP2003]神经网络 T1 https://neooj ...
- java第三讲课后动手动脑及代码编写
1. 类就是类型,对象就是这种类型的实例,也就是例子.类是抽象的东西,对象是某种类的实实在在的例子.例如:车是一个类,汽车,自行车就是他的对象. 对象的定义方法? (1)对象声明:类名 对象名: (2 ...
- yum源加速,替换为阿里云镜像
问题 使用yum命令安装mysql时,发现下载速度很慢,于是决定换成阿里的yum源 解决方法 参考自:https://www.jianshu.com/p/b7cd2f9fb8b7 首先备份一下原先的y ...
- bash shell——sum
#!/bin/bash # sum.sh # 获取随机数量的参数,相加并打印结果 # total= # # $# 表示参数的数量 # for 循环获取每个参数 # ${!i} 表示返回第i个参数 # ...
- Xamarin.Forms移动开发系列2:创建和调试
摘要 本文将介绍如何通过VS2019创建Xamarin.Forms应用程序,以及如何进行调试. 前言 本文介绍Xamarin.Froms应用程序的创建和调试. 开发环境 1.Visual Studio ...
- Ubuntu放弃战斗, Linux桌面的悲哀 - 简书
Ubuntu放弃战斗, Linux桌面的悲哀 - 简书 https://www.jianshu.com/p/86dd6e34ce91
- [LeetCode] 78. Subsets 子集合
Given a set of distinct integers, S, return all possible subsets. Note: Elements in a subset must be ...
- 各版本linux推荐的软件源
x64 Ubuntu 18.4 deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe mul ...
- springcloud(五,多个服务注册中心eureka)
spring cloud (一.服务注册demo_eureka) spring cloud (二.服务注册安全demo_eureka) spring cloud (三.服务提供者demo_provid ...