在我从事的大多数网络项目中,我总是需要用户的位置。我使用过 Maxmind 的 GeoIp,但它涉及您导入他们的数据集并且需要不断更新。还有其他免费和付费服务,但我只想要一些简单的东西,我可以在几秒钟内添加到任何网站。
所以这有点像诱饵,因为我有一个简单的解决方案,详细信息如下,但我想看看是否有其他人使用这种技术,是否有更好的解决方案,或者是否存在一些不可预见的陷阱。
I always end up needing the user's location on most web projects that I work on. I've used Maxmind's GeoIp, but it involves you importing their dataset and it needs constant updating. There are also other free and paid services, but I just wanted something simple that I could add to any site in a matter of seconds.
So this is sort of baited because I have a simple solution, detailed below, but I wanted to see if anyone else uses this technique and if there are any better solutions or if there are some unforeseen pitfalls.
发布评论
评论(3)
我目前使用的实现已经在其他几个问题中看到过,但我还没有将其视为选定的答案。
我在我的博客中详细介绍了这一点 thenullreference.com,但简而言之:
基本上,您需要做的就是加载 Google 的 API 加载器脚本:
然后您就可以访问多个属性,为您提供详细的位置信息。
您要查看的对象是 google.loader.ClientLocation
*注意,其中一些可能为 null
有关此 API 的更多信息,请查看 这里
还有其他人使用这个吗?有人使用过同样简单且更好的东西吗?这种方法有问题吗?
我不知道这个解决方案的覆盖范围/准确性,但我认为谷歌会不断更新它并且可能相当不错。
The implementation I currently use I've seen in a couple other questions, but I haven't seen it as the selected answer.
I've detailed this in my blog thenullreference.com, but here it is in short:
Essentially all you need to do is load Google's API loader script:
Then you have access to several properties that give you detailed location info.
The object you want to look at is google.loader.ClientLocation
*Note some of these can be null
For more info on this API check out here
Does anyone else use this? Does anyone have something that they use that is as simple and better? Are there issues with this approach?
I'm unaware of the coverage/accuracy of this solution, but I would think that Google keeps it updated and is probably pretty good.
我使用过 wipmania 免费 JSONP 服务,我不太确定它的准确性,但它非常简单使用:
检查此处运行的代码片段。
I've used the wipmania free JSONP service, I'm not really sure about its accuracy but it's really simple to use:
Check the snippet running here.
我使用 MaxMind GeoIP City/ISP/Organization(Web 服务),50,000 个查询的成本为 20 美元,并且始终更新(请参阅 http://www.maxmind.com/app/web_services#city)。我喜欢这样一个事实:我不需要担心数据库更新,因为这一切都在服务器上完成。
我使用 PHP 发送客户端 IP 地址,作为回报,我得到纬度、经度以及其他有用的信息,如区域代码、城市、大都市代码、区号、国家/地区、ISP 和组织名称(如果已知)。
I use the MaxMind GeoIP City/ISP/Organization (Web Service), this cost $20 for 50,000 queries and is always updated (see http://www.maxmind.com/app/web_services#city). I like the fact that I don't need to worry about database updates since it is all done on there server.
I'm using PHP to send the client IP address and in return I get the latitude, longitude as well as other useful like the region code, city, metropolitan code, area code, country, ISP, and organization name if known.