用于查找位置的最佳 node.js 模块?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16664623/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Best node.js module for finding location?
提问by karthick
I had found couple of node.js modulesfor finding the information about client location and network using ip address.
我找到了几个node.js 模块,用于使用 ip 地址查找有关客户端位置和网络的信息。
Requirements:
要求:
Location - country, city, state, latitude, longitude etc.
Network - Internet service Provider, Internet connection type and internet speed etc.
Data Accuracy - maximum possibility.
位置 - 国家、城市、州、纬度、经度等。
网络 - 互联网服务提供商、互联网连接类型和互联网速度等。
数据准确性 - 最大可能性。
Note:Looking for server side solution.
注意:寻找服务器端解决方案。
The above mentioned modules uses maxmind data. And i had read about the maxmind data accuracyas well.
上述模块使用maxmind 数据。我也阅读了有关maxmind 数据准确性的信息。
I am little confused to choose the above node.js modules and i like to know is there any better node.js frameworks available for finding information which met my requirement or any other language plugins which can be portable to node.js.
我对选择上述 node.js 模块有点困惑,我想知道是否有更好的 node.js 框架可用于查找满足我的要求的信息或任何其他可以移植到 node.js 的语言插件。
Any idea will be greatful.
任何想法都会很棒。
采纳答案by dom
Using IP-based geolocation is possible, but not very accurate. So I suggest you to think about going with a hybrid approach, like trying to get the users location via the HTML5 geolocation API inside the browser and fallback to the serverside if necessary.
使用基于 IP 的地理定位是可能的,但不是很准确。因此,我建议您考虑采用混合方法,例如尝试通过浏览器内的 HTML5 地理定位 API 获取用户位置,并在必要时回退到服务器端。
I took a look at the two most used geoip/-location modules available for node.js and they both use the datasets provided by MaxMind. AFAIK you have to keep these databases up-2-date manually, which is a clear downer. So you may consider writing a little sync service / script, which updates the database once per month. (More information on MaxMinds free solution can be found here).
我查看了 node.js 可用的两个最常用的 geoip/-location 模块,它们都使用 MaxMind 提供的数据集。AFAIK 你必须手动保持这些数据库更新 2 次,这是一个明显的障碍。所以你可以考虑写一个小的同步服务/脚本,它每个月更新一次数据库。(可以在此处找到有关 MaxMinds 免费解决方案的更多信息)。
kuno/GeoIPis a GeoIP binding, so at it's core it's using the libGeoIP C library, which is okay, but maybe not as portable as the pure JavaScript implementation bluesmoon/node-geoipoffers. Both are okay and it's up to you which library you like more. In terms of performance you have to do some benchmakrs (if this topic matters to you) … There is no general answer to the question, which type of module (C-binding/native) will be faster.
kuno/GeoIP是一个 GeoIP 绑定,所以它的核心是使用 libGeoIP C 库,这没问题,但可能不像纯 JavaScript 实现bluesmoon/node-geoip提供的那样可移植。两者都可以,这取决于您更喜欢哪个库。在性能方面,你必须做一些基准测试(如果这个主题对你很重要)......这个问题没有通用的答案,哪种类型的模块(C 绑定/本机)会更快。
If you're willing to spend a few bucks you could also look into MaxMinds Web Service, which is a simple REST API and will be the most precise way to go. The documentation is quite good –?so getting started with that won't be a problem.
如果您愿意花一些钱,您还可以查看MaxMinds Web Service,它是一个简单的 REST API,将是最精确的方法。文档非常好——所以开始使用不会有问题。
回答by brnrd
If you get the IP, you can always call an external service to get the location information such as freegeoip.netand using the request module.
如果拿到IP,就可以随时调用外部服务获取位置信息,比如freegeoip.net,使用request模块。
(ip, location) ->
url = 'http://freegeoip.net/json/' + ip
request.get url, (error, response, body) ->
if !error && response.statusCode == 200
data = JSON.parse body
location data
For the network infos, I don't have a solution, but I'm looking for one too.
对于网络信息,我没有解决方案,但我也在寻找解决方案。
回答by Ben Dowling
You can get all of the information you're after from my API at http://ipinfo.ioAPI:
您可以在http://ipinfo.ioAPI 上从我的 API 获取您需要的所有信息:
$ curl ipinfo.io
{
"ip": "67.188.232.131",
"hostname": "c-67-188-232-131.hsd1.ca.comcast.net",
"city": "Mountain View",
"region": "California",
"country": "US",
"loc": "37.4192,-122.0574",
"org": "AS7922 Comcast Cable Communications, Inc.",
"postal": "94043"
}
It supports JSONP and CORS, so you can use it either server or client side. More details are available at http://ipinfo.io/developers
它支持 JSONP 和 CORS,因此您可以在服务器端或客户端使用它。更多详细信息请访问http://ipinfo.io/developers

