问题描述
项目:我有一个以校友地址存储为lng/lat的MySQL数据库.我希望能够确定15个成员或更多的校友团体,它们彼此之间相距15英里.
Project: I have a MySQL database of alumni home address locations stored as lng/lat. I want to be able to identify groups of 15 members or more of alumni that live within a 15 mile radius of each other.
给出一个lng/lat,我该如何选择半径15英里范围内的其他lng/lat位置?我已经在Linux上安装了PEAR的PHP地理名称包.我尚不清楚我是否可以使用此软件包来帮助实现此功能.它包含半径例程,但它们似乎是用于返回信息,例如长度/纬度半径内的邮政编码.谢谢!
Given a lng/lat, how do I select the other lng/lat locations that are within a 15 mile radius? I've installed on Linux the PHP geonames package from PEAR. It isn't clear to me if I can use this package for aid in this function. It contains radius routines, but they appear to be for returning information such as postal codes within a lng/lat radius. Thanks!
推荐答案
您需要使用 Haversine公式.您会发现许多在线示例,向您展示如何在PHP和SQL中实现该公式.
You'll need to look into using the Haversine Formula. You'll find plenty of online examples showing you how to implement the formula in both PHP and SQL.
Google 有一个很好的MySQL示例:
SELECT id, ( 3959 * acos( cos( radians(37) ) * cos( radians( lat ) ) * cos( radians( lng ) - radians(-122) ) + sin( radians(37) ) * sin( radians( lat ) ) ) ) AS distance
FROM markers HAVING distance < 25 ORDER BY distance LIMIT 0 , 20;
这篇关于定位半径不超过15英里的最近的lng/lat位置的方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!