按邮政编码距离排序 [英] ORDER BY Zip Code Distance
问题描述
我已成功将以下文章中包含的ASP代码转换为PHP:
http://www.4guysfromrolla.com/webtech/040100-1.shtml
如上所述,高低纬度经度预先计算
并传递给查询。
SELECT *
从地点
在哪里纬度< = $ HighLatitude
和纬度> = $ LowLatitude
和经度> = $ LowLongitude >
AND经度< = $ HighLongitude
然后我使用纬度和经度计算实际距离
每个zip返回。
这很好用,可以节省很多周期。这种技术的缺点是
无法按距离排序。有人可以建议一个简单的方法来计算和查询中的ORDER BY距离吗?
谢谢!
I have successfully converted the ASP code included in the following article
to PHP:
http://www.4guysfromrolla.com/webtech/040100-1.shtml
As described the high and low latitudes and longitudes are pre-calculated
and passed to the query.
SELECT *
FROM Locations
WHERE Latitude <= $HighLatitude
AND Latitude >= $LowLatitude
AND Longitude >= $LowLongitude
AND Longitude <= $HighLongitude
I then calculate the actual distance using the latitude and longitude for
each zip returned.
This works great and saves lots of cycles. The downside to this technique is
the inability to sort by distance. Can someone suggest a simple way to
calculate and ORDER BY distance within the query?
Thanks!
推荐答案
HighLatitude
和纬度> =
HighLatitude
AND Latitude >=
LowLatitude
和经度> ; =
LowLatitude
AND Longitude >=
LowLongitude
和经度< =
LowLongitude
AND Longitude <=
这篇关于按邮政编码距离排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!