我的目标是在我的最新项目中创建功能,最好使用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.
>空间键和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;
(示例取自上面的链接)