地理定位的最佳方法是什么?
最近,地理定位在技术领域非常流行。通过 IP、手机信号塔、GPS、使用浏览器插件、HTML5?、移动设备...
由于我即将在我们的网站上添加一些地理定位功能,所以我想知道什么是最好的方法。是否有一些 API 混合使用了所有这些技术?或者至少,您建议我使用什么 API/服务?
我正在开发的服务不需要 100% 准确,所以我对地理 IP 很满意,但如果有一种简单的方法可以做得更好,为什么不呢。
使用的技术有php、javascript、ajax、java。
Lately geo-targeting has been pretty popular in technology. By IP, cell tower, GPS, using browser plugins, HTML5?, mobile devices ...
Since I'm about to add some geo-targeted features on our site, I wanted to know what's the best approach. Is there some API that uses a mix of all those technologies? Or at least, what API/service would you recommend I use?
The service I'm working on doesn't need to be 100% accurate, so I'm OK with geo-IP, but if there's an easy way to do better, why not.
Technologies used are php, javascript, ajax, java.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
无论你做什么,请不要根据用户的 IP 设置网站的语言,然后使其几乎不可能更改,除非你知道所述语言并且你觉得浪费时间(例如 eBay 和 Paypal 等) )。使用浏览器的语言。
比如说,法国并不是每个人都会说或想说法语。
我想这与你的问题不太相关,但我觉得有必要对此抱怨一下,抱歉:)
Whatever you do please please please don't set the language of your website based on the user's IP, and then make it almost impossible to change unless you know said language and you feel like wasting hours (like ebay and paypal, among others, do). Use the browser's language.
Not everyone in, let's say, France speaks or wants to speak French.
I guess it's not very related to your question but i felt the need to rant about this, sorry :)
GEO IP 可能是目前最好的方法。
HTML5 看起来很有前途,但要得到广泛支持还需要一段时间。即使如此,它也需要明确的用户批准,这限制了使用它的可能性(例如自动重定向到网站的特定国家/地区版本)
GEO IP is probably the best approach for now.
HTML5 looks promising, but it'll be a while before it's widely supported. And even then it requires explicit user approval, which kind of limits the possibilities for using it (for example auto-redirecting to a country specific version of a website)
首先尝试免费的 http://api.hostip.info?ip=xxxx ( www.hostip.info 网站)
它将以 xml 结构为您提供城市和国家/地区。我在 http 服务器上有一个用 PHP 编写的小型代理脚本,一个 html 页面使用 ajax 调用该脚本,并使用 Google 地理编码 api 以文本形式和在 Google 地图上显示信息。稍后您可以轻松地将 api.hostip.info 替换为其他 api。
For a start try the free http://api.hostip.info?ip=x.x.x.x (www.hostip.info for website)
It'll give you city and country in a xml structur. I've a small proxy-script writen in PHP on the http-server, which a html page calls with ajax and show the infomation in text and on a Google map using the Google geocoding api. Later on you can easy replace the api.hostip.info with an other api.
默认情况下,我会使用 IP 地址检测,然后可以选择使用 Javascript/HTML5
navigator.geolocation
API(如果存在)请求更具体的位置。 (例如,在 iPhone Safari 中)大多数用户仍在使用本身不知道位置的设备,因此可用的插件无论如何都不会比 IP 地址检测获得更好的位置。 (或者,他们会提示用户手动输入数据,这很烦人)
I would use IP address detection by default, and then optionally ask for a more specific location using the Javascript/HTML5
navigator.geolocation
API when present. (For example, in iPhone Safari)Most users are still using devices that don't know the location themselves, so plugins that are available will not get a better location than IP address detection does anyway. (Alternatively, they'll prompt users to manually enter data, which is annoying)
麦克斯头脑很好。但如果您正在寻找免费的解决方案,您可能需要考虑使用 javascript 地理编码器。最终他们将支持地址和国家/地区,但现在,他们只提供纬度和经度。
Max Mind is good. But if you are looking for a free solution, you may want to consider using the javascript geocoder. Eventually they will support addresses and country, but right now, they only give you a latitude and longitude.