We don’t allow questions seeking recommendations for software libraries, tutorials, tools, books, or other off-site resources. You can edit the question so it can be answered with facts and citations.
Closed 6 years ago.
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(4)
更新:我刚刚在 BBC 新闻网站上看到邮政编码数据将从本月起免费。鉴于此,我会使用这些数据。我会寻找该数据库的 API。
这是一篇关于 Google 地理编码的好文章API
Update: I just saw on the BBC News site that the PostCode Data will be Free from this month. In light of this, I would use this data. I would have a look for APIs to this database.
Here is a good article on the Google Geocoding API
至少在美国(我完全不知道任何其他国家/地区的邮政编码格式 - 但如果它们映射到长/纬度,这应该可行),您应该能够使用半正矢公式计算出其中的邮政编码给定的地理空间半径。
简单来说,你必须有一个邮政编码->长/纬度表。然后,根据给定的邮政编码(坐标),您可以通过数学方式确定该点给定距离内的所有纬度和经度坐标 - 然后您获取这些近似坐标并转换回邮政编码,然后查询邮政编码内的成员。
之后,只需将它们绘制在地图上即可。下面将提供比我能提供的更多详细信息,因为它解释了数学并实际上将其转换为有效的 MySQL 查询以帮助您入门:
http://www.scribd.com/doc/2569355/Geo-Distance-Search-with-MySQL
At least within the United States (I am completely ignorant of any other country's postal code format -- but if they map to Long/Lat, this ought to work) you should be able to use the Haversine Formula to work out the ZIP codes within a given geospatial radius.
Simply put, you must have a postal code -> long/lat table. Then, from a given postal code (coordinate) you can mathematically determine all latitude and longitudinal coordinates within a given distance of that point -- then you take those approximate coords and convert back to zip, then query for members within zip codes.
After that, it's a matter of plotting them out on a map. The following will give MUCH more detail than I could, as it explains the math and actually translates it into a working MySQL query to get you started:
http://www.scribd.com/doc/2569355/Geo-Distance-Search-with-MySQL
您在某些时候可能会遇到的一件事是必须计算两点(纬度/经度)对之间的距离。最著名的算法之一是Haversine Forumla。我已经根据我找到的一些 C 代码编写了这个实现(不记得原作者是否注明出处)。它是这样的:
其中 DistantUnit 是一个简单的枚举,而 LatLng 本质上只是一个具有两个双属性的结构或类。
One thing you will probably encounter at some point is having to calculate the distance between two points (latitude/longitude) pairs. One of the best known algorithms is the Haversine Forumla. I've written an implementation of this, based on some C code I found (can't remember the original author to credit them). It goes something like this:
Where DistantUnit is a simple enum and LatLng is essentially just a struct or class with two double properties.
几个月前我也做过类似的事情。给定一个 IP 地址,我需要知道该服务应在我们自己的服务器上运行的封闭城镇/城市。从一个我不再知道的网站上,我得到了世界各地的纬度/经度/城市位置列表。该表包含大约 8 个 mio 条目。
正如 Dan Diplo 建议的那样,您需要距离来进行此类查询。我的查询是找到给定纬度/经度坐标的最近位置。
使用与 Dan Diplo 类似的函数,我创建了一个索引,用于计算数据库条目 (latlng1) 和零 (latlng2) 的距离。该索引仅用于进行索引扫描以减少数据集 - 它无助于找到最终值。最后,您必须查询您搜索的数据以及到零的距离以减少搜索集。
因此一次查询花费了大约 100 毫秒。但是你必须使用 Diplo 的函数作为 SQL 索引,这对于当前提供数学函数的数据库来说不应该是问题。
I did something similar few months ago. Given an IP address i needed to know the closes town/city where this service should run on our own servers. From a website i dont know any more i got a list of lat/lng/city locations all around the world. The table contained around 8 mio entries.
As Dan Diplo suggest you will need the distance for such queries. My Query was to find the closest location for a given lat/lng coordinate.
Using a similar function as Dan Diplo's i created an index which calculated the distance of the DB entry (latlng1) and zero (latlng2). This index is only used to get an index scan to reduce the data set - it doestn help finding the final value. Finally you have to query for the data you search AND the distance to zero to reduce the search set.
Thus a query took around 100ms. But you have to use Diplo's function as a SQL index which shouldnt be a problem on current databases providing mathematical functions.