GeoIP 最近(最近)国家

发布于 2024-09-13 04:26:21 字数 191 浏览 7 评论 0原文

伙计们,我有一个小问题,我试图在基于 GeoIP 的系统上找到一些示例,该系统根据最近的邻国扩展搜索。例如,访问者来自英国,并尝试查找来自法国、西班牙、比利时等的 IP,而不是巴西、阿根廷、中国。那么我怎样才能从给定的国家/IP获取最近的国家并扩大距离呢?

编辑:我正在使用免费的 Max-mind 版本,因为我不太关心城市。我的项目是基于 C# 的。

Guys i have a little problem, i tried to find some examples on GeoIP based system that expands searches based on nearest neighbor countries. For example the visitor is from UK and tries to find IPs from France, Spain, Belgium etc. not for example Brazil, Argentina, China. So how can i get nearest countries from a given country/IP and expand incrementing the distance?

Edit: I'm using the free Max-mind version, since i don't care about cities that much. And my project is C# based.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

神回复 2024-09-20 04:26:21

好吧,减少问题的第一步是使用基本的地理知识,并按大陆对国家/地区进行分类

从那里您可以列出给定大陆内的距离,并根据这些“距离”或“权重”进行排序。

如果您想变得更奇特,首都城市之间的地理距离(例如公里或英里)应该是“足够好”的近似值。我敢打赌,您甚至可以通过在互联网上进行一些搜索来找到这样的列表。

从那里你有“邮局问题”(Knuth)或“最近邻居搜索”优化问题,在这种情况下,我怀疑您可以[REWORDED]简单地在大陆分区内进行线性搜索。如果您需要更好的性能,那么近似算法方法就足够了。 (答案不能保证是最佳解决方案,但在大多数情况下应该是合理的)

请注意,这种基于地理的“路由”形式在少数特殊情况下很弱,例如古巴,它不由于政治关系,可以从其(天真的)明显的地理邻居美国和一些“黑洞”类型的国家获得互联网接入。我怀疑朝鲜和西藏也有类似的情况。

Well, the first step to reduce the problem is to use basic geography, and categorize the countries by continents.

From there you can make a list of distances of within a given continent, and sort based on those "distances" or "weights".

The geographic distance (e.g. km or miles) between capital cities should be a "good enough" approximation to get started if you want to be fancy. I bet you could even find such a list with a bit of searching on the Internet.

From there you have the "post-office problem" (Knuth) or "nearest neighbor search" optimization problem, and in this case I suspect you can [REWORDED] simply go with a linear search within the continents partitions. If you need better performance, then an approximate algorithm approach should suffice. (answers are not guaranteed to be best solution, but should be reasonable most of the time)

Note this form of geography based "routing" is weak in a few exceptional cases, such as Cuba, which does not get Internet access from its (naive) obvious geographic neighbor, USA, and some "black-hole" type countries due to political relations. North Korea and Tibet I suspect are similar cases.

梦醒时光 2024-09-20 04:26:21

Maxmind 为您提供每个国家/地区的纬度/经度,因此您只需计算您所在国家/地区与其他国家/地区的差异即可。请参阅此线程进行地理位置距离计算< /a> 或使用您选择的库。

但请记住,一个国家/地区的地理位置只是该国家/地区某个地方的一个单个点,而不是距您最近的点。

Maxmind gives you the Lat/Long of each country, so you can just calculate the difference of your country to the others and you're done. See this thread for geolocation distance calculation or use a library of your choice.

But keep in mind the the geo location of a country is just a single point somewhere in this country and not the nearest point to you.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文