如何确定给定的经度和纬度点代表哪个城市?
我目前正在使用一个非常大的地理 IP 数据库,该数据库是我从许多免费软件网站中混合构建的。
问题是 - 所有这些数据库的映射是:map: (ip) -> (纬度,长)
我正在寻找一种方法,通过城市的分辨率(如果可能的话)离线推断出这些纬度和长点的位置。
谢谢
I'm currently using a very large geo-ip database that i've built as a mixture from many freeware sites.
The problem is - the mapping of all those database is : map: (ip) -> (latitude,long)
I'm looking for a way that will deduce the location of those latitude and long points by resolution of a city and if possible - offline.
thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可能想尝试一下 Google 地理编码 http://code.google.com /intl/en/apis/maps/documentation/geocoding/
You may want to try Google Geocoding http://code.google.com/intl/en/apis/maps/documentation/geocoding/
要离线执行此操作,您需要一个长/纬度坐标数据库,例如: http:// www.maxmind.com/app/worldcities
然后为了将经度/纬度与城市相匹配,您必须构建一个算法将其范围缩小到误差范围内。
一种暴力方法可能是使用毕达哥拉斯定理来测量距离,但这会很快耗尽你的 CPU。更好的方法可能是首先排除高于或低于目标纬度/经度 1 或更多的结果,然后对剩余结果进行测量。
to do it offline, you'll need a database of long/lat coordinates, such as this: http://www.maxmind.com/app/worldcities
then to match the long/lat to the cities, you'll have to build an algorithm which narrows it down to within a margin of error.
a brute-force method might be to measure the distance by using pythagoras' theorem, but that would rapidly kill your CPU. a better way may be to start by excluding results that are 1 or more above or below your target lat/long, then do your measurements on the remaining results.
如果您确实需要离线信息,您可以从 citycsv.com 获取城市和地区的纬度/经度信息。查询纬度/经度数据并获取城市或地区将很容易。然而,正如所述,谷歌将能够通过其在线地理编码工具为您节省大量开销。
你可以通过 cron 作业以突发模式(每天最多 2.500)运行 google 的地理编码,并在......的过程中填充你的离线数据库。
you can get city and region lat/lon information from citycsv.com if you really need your info offline. It would be easy to query the data for lat/lon and get a city or region back. However as stated google would be able to take a lot of overhead off your hands with their online geocoding tools.
you could run google's geocode in burst-mode (2.500 max per day) through a cron job and fill up your offline database over the course of ....