如何找到用户访问网站期间的位置?

发布于 2024-10-29 07:02:13 字数 126 浏览 1 评论 0原文

因此,当用户登录我的网站主页时,我希望能够找到用户的位置(即使只是到城市/城镇级别)。我认为这并非不可能,因为谷歌似乎在您登录其主页时会这样做,它似乎会将您的搜索结果调整到您所在的区域,等等。

我会研究什么才能做到这一点?

So, I want to be able to find the users location (even if it's only down to the city/town level), when they log onto the home page of my website. I figured this isn't impossible because Google seems to do it when you log on their main page, it seems to gear your search results toward your area, etc.

What would I look into to be able to do this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

冷…雨湿花 2024-11-05 07:02:13

您可以使用 GeoIP 定位服务,这些服务具有不同的精度级别。可能还有其他 IP 位置数据库提供商。

另一种选择是尝试使用 HTML5 位置服务,例如 http://html5demos.com/geo 和 < a href="http://dev.w3.org/geo/api/spec-source.html" rel="noreferrer">http://dev.w3.org/geo/api/spec-source.html< /a>.

You can use GeoIP location services, who have various levels of accuracy. There may be other providers of IP-location databases too.

Another option is to try to use HTML5 location services, such as in http://html5demos.com/geo and http://dev.w3.org/geo/api/spec-source.html.

对岸观火 2024-11-05 07:02:13

您需要使用 IP 地理/协同定位 API,例如 这个 以及许多其他 API。 拥有一项仅需要注册的免费服务。

您还可以下载包含地理代码信息的数据库。这将适用于一定的分辨率,但数据库代表静态快照,并且现实可能会随着时间的推移而发生显着变化。 这是一个免费提供的 CSV 文件,可以帮助您开始在本地数据库方面的事情。 CSV 文件(有点旧,最后更新于 2009 年 8 月)包含 59,000 个条目。

You need to use an IP geo/co-location API such as this one and many others. This one boasts a free service requiring only registration.

You can also download databases with geo code information. This will work to certain resolution but the db represents a static snapshot and reality may veer significantly over time. Here is a freely available CSV file that could get you started on the local db side of things. The CSV file (which is a bit old, was last updated August 2009) contains 59,000 entries.

绝影如岚 2024-11-05 07:02:13

您可以 a) 使用在线服务来查找位置 - 许多服务都有 API,或者 b) 网络上有大量数据库可供您下载。根据您需要的分辨率,您可能需要付费。但国家分辨率当然是免费的。尝试用谷歌搜索“geo ip”或类似的内容。

YOu can either a) use an online service to look up the location - many have an api, or b) there are numerous databases floating around the web that you can download. Depending on the resolution you need, you may have to pay. But country resolution is certainly available for free. Try googling "geo ip" or similar.

不语却知心 2024-11-05 07:02:13

由于我遇到的一些问题,我想添加另一个解决方案。所有早期的答案都非常有效。但如果您要使用 HTML Geolocation API,则必须向用户请求位置许可。 IPinfo 工作得很好,但一些广告拦截器(如 ublock)会阻止来自客户端的 API 命中。

如果您可以将 DNS 管理器更改为 CLoudflare,那么您可以使用 Cloudflare IP Geolocation。您可以参考Don的回答此处

I would like to add another solution because of some issues I faced. All the earlier answers work very well. But if you'll use HTML Geolocation API you'll have to ask for the location permission from the user. IPinfo works very well but some adblockers like ublock will block the API hit from the client side.

If it is possible for you to change your DNS manager to CLoudflare then you can use Cloudflare IP Geolocation. You can refer to Don's answer here

英雄似剑 2024-11-05 07:02:13

如果您不关心超精细的准确性,并且不想通过请求用户访问其位置的权限的警报来惹恼用户,那么您可以使用类似 FreeGeoIP。我写了一个小的 jQuery 插件来利用它。请参阅定位器。也支持 jsonp 请求,因此您可以从任何网站使用它,包括仅静态 html 网站。

If you don't care about super-fine accuracy, and you don't want to annoy your user with an alert requesting their permission to access their location, then you can make use of something like FreeGeoIP. I've written a small jQuery plugin that makes use of this. See the Locaternator. Supports jsonp requests too so you can use it from any website, including static html only webs.

长发绾君心 2024-11-05 07:02:13

您可以在 HTML5 中使用 navigator.geolocation.getCurrentPosition。它将是相当跨平台的,您可以将其构建到向数据库报告的网页中。
请参阅

http://html5demos.com/geo
http://www.w3.org/TR/geolocation-API/ < br>
http://diveintohtml5.info/geolocation.html

you can use navigator.geolocation.getCurrentPosition in HTML5.It would be reasonably cross-platform and you could build it into web pages that report back to your database.
See

http://html5demos.com/geo
http://www.w3.org/TR/geolocation-API/
http://diveintohtml5.info/geolocation.html

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文