从ip地址获取用户的经度和纬度的最简单方法是什么? [英] What's the simplest way to get a user's latitude and longitude from an ip address

查看:175
本文介绍了从ip地址获取用户的经度和纬度的最简单方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我总是最终需要用户在我工作的大多数Web项目上的位置。我已经使用了 Maxmind的GeoIp ,但它涉及到导入他们的数据集并需要不断更新。还有其他的免费和付费服务,但我只想简单一点,我可以在几秒钟内添加到任何网站。



所以这是一个诱饵,因为我有一个简单的解决方案,下面详细介绍,但我想看看是否有其他人使用这种技术,如果有更好的解决方案或如果有一些不可预见的陷阱。

解决方案

我目前使用的实现我已经在其他一些问题中看到过,但我没有我没有把它看作是选定的答案。



我在我的博客中详细介绍了这一点 thenullreference.com ,但这里简而言之: b
$ b




基本上所有您需要做的就是加载Google的API加载器脚本:

 < script type =text / javascriptsrc =http(s)://www.google.com/jsapi>< / script> 

然后你可以访问几个属性,给你详细的位置信息。



您要查看的对象是 google.loader.ClientLocation


  • ClientLocation.latitude

  • ClientLocation.longitude

  • ClientLocation.address.city

  • ClientLocation.address.country

  • ClientLocation.address.country_code - ISO 3166-1国家代码

  • ClientLocation.address.region - 美国国家/地区特定区域
  • >


*请注意其中一些可以为空



有关此API检查的更多信息此处



确实其他人使用这个?有没有人有他们使用的东西是简单和更好?这种方法有问题吗?



我不知道这个解决方案的覆盖范围/准确性,但我认为Google会更新它,并且可能相当不错。

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.

解决方案

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:

<script type="text/javascript" src="http(s)://www.google.com/jsapi"></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

  • ClientLocation.latitude
  • ClientLocation.longitude
  • ClientLocation.address.city
  • ClientLocation.address.country
  • ClientLocation.address.country_code - ISO 3166-1 country code
  • ClientLocation.address.region - country specific region in US this is state

*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.

这篇关于从ip地址获取用户的经度和纬度的最简单方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆