根据经纬度从mysql获取结果

Get results from mysql based on latitude longitude(根据经纬度从mysql获取结果)
本文介绍了根据经纬度从mysql获取结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我有一个 mysql 数据库和 2 个表,比如说客户和学校.现在每个表都有纬度和经度列.我需要做一个选择,例如从第二个表中选择,其中学校位于第一个表中一个记录的给定半径内.应根据纬度和经度进行计算.PS:我用的是 PHP.

I have a mysql Database and 2 tables let's say clients and schools. Now each table has columns latitude and longitude. And I need do make a SELECT for example from second table where schools are in a given radius of one record from first table. Calculations should be made based on latitude and longitude. PS: I am using PHP.

推荐答案

您可以使用 计算距离余弦球面定律:

SELECT DEGREES(ACOS(SIN(RADIANS(clients.latitude)) * SIN(RADIANS(schools.latitude)) + 
                    COS(RADIANS(clients.latitude)) * COS(RADIANS(schools.latitude)) 
                                                   * COS(RADIANS(clients.longitude 
                                                               – schools.longitude)))) 
       * 60 * 1.1515 * 1.609344 AS distance
FROM clients, schools HAVING distance < $radius

RADIANS(X) -度到弧度
ACOS(X) - 反余弦X的,即余弦为X的值
DEGREES(X) - 弧度到度

RADIANS(X) - degrees to radians
ACOS(X) - the arc cosine of X, that is, the value whose cosine is X
DEGREES(X) - radians to degrees

60 - 度数
1.1515 - 海里
中的英里1.609344 - 一英里的公里

60 - minutes in a degree
1.1515 - miles in a nautical mile
1.609344 - kilometres in a mile

这篇关于根据经纬度从mysql获取结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

In PHP how can you clear a WSDL cache?(在 PHP 中如何清除 WSDL 缓存?)
failed to open stream: HTTP wrapper does not support writeable connections(无法打开流:HTTP 包装器不支持可写连接)
Stop caching for PHP 5.5.3 in MAMP(在 MAMP 中停止缓存 PHP 5.5.3)
Caching HTTP responses when they are dynamically created by PHP(缓存由 PHP 动态创建的 HTTP 响应)
Memcached vs APC which one should I choose?(Memcached 与 APC 我应该选择哪一个?)
What is causing quot;Unable to allocate memory for poolquot; in PHP?(是什么导致“无法为池分配内存?在 PHP 中?)