Javascript 如何检测访问者的国家/地区?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4179000/
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
How to detect country / location of visitor?
提问by Lupo
Possible Duplicate:
Location detecting techniques for IP addresses
可能的重复:
IP 地址的位置检测技术
For our website it's important to know from exactly which country our visitor is coming from.
对于我们的网站,重要的是要知道我们的访问者来自哪个国家。
I guess the best answer for my question would be the simple geo location feature of current browser systems, which just ask the user if the website is allowed to see his geographic location: http://dev.w3.org/geo/api/spec-source.html
我想我的问题的最佳答案是当前浏览器系统的简单地理位置功能,它只是询问用户是否允许网站查看他的地理位置:http: //dev.w3.org/geo/api/规范-source.html
but I don't want to bother visitor with questions, I would love to automatically detects the visitor's location (country should be enough.)
但我不想打扰访问者的问题,我很想自动检测访问者的位置(国家应该足够了。)
What's the best way to do this? - what ip database would be the best? - is the browser header trustable enough to detect his country? (en-us en-en en-ca?) What's the best solution?
做到这一点的最佳方法是什么?- 什么 ip 数据库会是最好的?- 浏览器标头是否足够可信以检测他的国家?(en-us en-en en-ca?) 最好的解决方案是什么?
采纳答案by Andy
NetImpactprovide a free API for geolocation lookup by IP, ProgrammableWeb also has a roundupof GeoIP lookup providers. This involves a small amount of latency while your application completes an API call (unless your application can use a non-blocking call) but is the least intrusive manner of detecting a visitor's country of origin.
NetImpact提供通过IP地理定位查找免费的API,ProgrammableWeb也有一个综述的GeoIP查找供应商。这涉及您的应用程序完成 API 调用时的少量延迟(除非您的应用程序可以使用非阻塞调用),但这是检测访问者原籍国的干扰最少的方式。
回答by Pointy
The browser header just tells you what languagethe user wants to see. A Spanish-speaking person on a business trip to Japan probably wants to see websites in Spanish.
浏览器标题只是告诉您用户希望看到什么语言。去日本出差的说西班牙语的人可能希望看到西班牙语网站。
I think you can use reverse-IP services to make a guess, but if it's for commerce purposes I think you have to askthe user to tell you.
我认为您可以使用反向 IP 服务进行猜测,但如果是出于商业目的,我认为您必须要求用户告诉您。
Similarly with geo-location: the physical position of the computer may or may not be relevant to the needs of the user browsing the site.
与地理位置类似:计算机的物理位置可能与浏览站点的用户的需求相关,也可能不相关。
回答by Drew
Have a look at this page on the Google Maps API: http://code.google.com/apis/maps/documentation/javascript/basics.html#DetectingUserLocation
在 Google Maps API 上查看此页面:http: //code.google.com/apis/maps/documentation/javascript/basics.html#DetectingUserLocation
回答by relima
http://www.iplocationtools.com/samples.htmlalso presents a good set of apis to do this. I have used their system before and they were quite reliable.
http://www.iplocationtools.com/samples.html也提供了一套很好的 api 来做到这一点。我以前用过他们的系统,他们非常可靠。