我的方针是在我的最新项目中建设成果,最好行使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";
这是从或人的博客中提取的.
我没有关于注册率或用户数目的任何数字,由于它仍在开拓中.
我将不胜谢谢任何可以用来查找特定半径内匹配用户的反馈或其他要领.
最佳谜底
在版本4.1中有mySql的GIS和空间扩展,请拜见here.从描写中可以发明,它用于办理相同此处的题目:
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;
(示例取自上面的链接)
(编辑:湖南网)
【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!
|