我的目标是在我的最新项目中创建功能,最好使用PHP.每个用户注册后,他们将输入他们的邮政编码.然后希望我可以使用“开放街道地图”将其转换为经/纬度.
无论如何,我希望能够找出当前用户附近的其他用户.
我见过很多人使用Haversine公式,但这意味着用户要查询其他用户的详细信息以计算距离.我可以缓存它,但是随着新用户的注册,它很快就会过时了.
运行以下查询会对我的系统产生什么样的影响?
sql = "SELECT zipcode,( 3959 * acos( cos( radians( {$coords['latitude']} ) )
* cos( radians( latitude ) ) * cos( radians( longitude )
- radians( {$coords['longitude']} ) )
+ sin( radians( {$coords['latitude']} ) ) * sin( radians( latitude ) ) ) )
AS distance FROM zipcodes HAVING distance <= {$radius} ORDER BY distance";
这是从某人的博客中提取的.
我没有关于注册率或用户数量的任何数字,因为它仍在开发中.
我将不胜感激任何可以用来查找特定半径内匹配用户的反馈或其他方法.
A GIS (geographic information system)
stores and looks up objects which have
one or more spatial attributes,such
as size and position,and is used to
process such objects. A simple example
would be a system that stores
addresses in a town using geographic
coordinates. If this rather static
data was then combined with other
information,such as the location of a
taxi-cab,then this data could be used
to find the closest cab to a certain
location.
它向MySql添加了一些东西,例如:
>空间键和POINT类型:
创建表地址(
地址CHAR(80)NOT NULL,
address_loc POINT不为NULL,
主键(地址),
空间键(address_loc)
);
>转换程序
插入地址值(‘Foobar street 12’,GeomFromText(‘POINT(2671 2500)’));
> GIS计算功能
选择
c.cabdriver,
ROUND(GLength(LineStringFromWKB(LineString(AsBinary(c.cab_loc),
AsBinary(a.address_loc)))))
AS距离
从出租车c,地址a
ORDER BY距离ASC LIMIT 1;
(示例取自上面的链接)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。