| 我的目标是在我的最新项目中创建功能,最好使用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;
 (示例取自上面的链接)
 (编辑:鹰潭站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |