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.ClientLocationClientLocation.latitude ClientLocation.longitudeClientLocation.address.cityClientLocation.address.countryClientLocation.address.country_code - ISO 3166-1 country codeClientLocation.address.region - country specific region in US this is state*Note some of these can be nullFor more info on this API check out hereDoes 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地址获取用户的经度和纬度的最简单方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-11 17:27