Html HTML5 地理定位如何工作?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4213410/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 05:19:46  来源:igfitidea点击:

How does HTML5 Geolocation Work?

browserhtmlgeolocation

提问by danidacar

Chrome and Firefox have HTML Geolocation implemented.

Chrome 和 Firefox 实现了 HTML 地理定位。

My question is: how does it work? Do they have a Database locally and get the information from the provider then try to match it?

我的问题是:它是如何工作的?他们是否在本地有一个数据库并从提供者那里获取信息然后尝试匹配它?

Where is the DB stored ? Can it be accessed ?

数据库存储在哪里?可以访问吗?

Update1: the only downside to geolocation is the browser has to ask the user for permission and this is really a bad thing for usability. I understand the security issue but still I don't see how this will become a popular solution.

更新 1:地理定位的唯一缺点是浏览器必须征求用户的许可,这对于可用性来说确实是一件坏事。我理解安全问题,但我仍然不明白这将如何成为一个流行的解决方案。

Update2 : Firefox is using a Google WebService to detect the location. Now this seems very strange considering they are competitors now. Also this behavior it's really unexpected for me... I hopped each browser will have it's on (maybe offline) solution.

更新 2:Firefox 正在使用 Google WebService 来检测位置。现在考虑到他们现在是竞争对手,这似乎很奇怪。此外,这种行为对我来说真的出乎意料......我希望每个浏览器都会有它的(可能是离线的)解决方案。

Update3 : So the browsers actually sniff for routers using your wireless network card?

更新 3 :所以浏览器实际上使用您的无线网卡嗅探路由器?

Update4 : In the end what informations is the browser sending to the the google webservice ? The detected SSID seems ok ( and it makes sense that if they are tracked by google based on their physical position to make a lookup in the database for matching informations ) but how does it work so well in country where google didn't scanned this ? The other info your browser is sending is your ip but this is not enough to pin point your exact location right ?

Update4:浏览器到底向google webservice发送了什么信息?检测到的 SSID 似乎没问题(如果谷歌根据他们的物理位置跟踪他们以在数据库中查找匹配信息是有道理的),但它如何在谷歌没有扫描的国家如此有效?您的浏览器发送的其他信息是您的 IP,但这不足以确定您的确切位置,对吗?

Regarding other browsers that might implement this. How should they do it ? The api is not documented only the old deprecated GEAR api gives some clue. So this is not really public.

关于可能实现这一点的其他浏览器。他们应该怎么做?api 没有记录,只有旧的已弃用的 GEAR api 提供了一些线索。所以这并不是真正公开的。

采纳答案by npdoty

For what it's worth, the API specification itself is agnostic to the geolocation implementation. So while it's true that Mozilla Firefox and Google Chrome both rely on network-enabled geolocation via Google's Location Service database, that's not a requirement of the standard. For example, Mobile Safari on your iPhone will in some cases use GPS rather than WiFi-triangulation or cell-site geolocation, depending on what location service is most accurate and accessible at a given moment.

就其价值而言,API 规范本身与地理定位实现无关。因此,虽然 Mozilla Firefox 和 Google Chrome 确实都依赖于通过 Google 的位置服务数据库启用网络的地理定位,但这并不是标准的要求。例如,在某些情况下,iPhone 上的 Mobile Safari 将使用 GPS 而不是 WiFi 三角测量或蜂窝站点地理定位,具体取决于在给定时刻哪种定位服务最准确且可访问。

And we can hope that future browsers will provide some choice of the location provider. I agree that it would be good for user privacy and functionality if browsers supported geolocation technologies that didn't require sending a list of WiFi IDs to a third party; I suspect that as GPS sensors are more often integrated into smartphones and laptops, we'll see browsers that let you use GPS sensing for the W3C Geolocation API. It might also be nice to have a feature for desktop computers where the location can be manually specified in browser settings, this would also be compatible with the current spec.

我们希望未来的浏览器能够提供一些位置提供者的选择。我同意,如果浏览器支持不需要向第三方发送 WiFi ID 列表的地理定位技术,这对用户隐私和功能都有好处;我怀疑随着 GPS 传感器越来越多地集成到智能手机和笔记本电脑中,我们将看到浏览器让您可以将 GPS 传感用于 W3C 地理定位 API。为台式计算机提供一个可以在浏览器设置中手动指定位置的功能也可能很好,这也将与当前规范兼容。

回答by Chetan

First, an amazing demo

首先,一个惊人的演示

Try thisin Chrome.

在 Chrome 中试试这个

How it works

这个怎么运作

Hereis your answer. Click on "How Google Chrome determines your location".

是你的答案。点击“谷歌浏览器如何确定您的位置”。

From that page:

从该页面:

If you allow Google Chrome to share your location with a site, the browser will send local network information to Google Location Services to get an estimate of your location. The browser can then share your location with the requesting site. The local network information used by Google Location Services to estimate your location includes information about visible WiFi access points, including their signal strength; information about your local router; your computer's IP address. The accuracy and coverage of Google Location Services will vary by location.

Google Chrome saves your location information so that it can be easily retrieved. This information is periodically updated; the frequency of updates depends on changes to your local network information.

如果您允许 Google Chrome 与某个站点共享您的位置,则浏览器会将本地网络信息发送到 Google 位置服务以获取您的位置估计值。然后浏览器可以与请求站点共享您的位置。Google 位置服务用于估计您的位置的本地网络信息包括有关可见 WiFi 接入点的信息,包括它们的信号强度;有关您本地路由器的信息;您计算机的 IP 地址。Google 位置服务的准确性和覆盖范围因位置而异。

谷歌浏览器会保存您的位置信息,以便轻松检索。这些信息会定期更新;更新频率取决于您本地网络信息的变化。

Also, I believe that Google Location Services contains a database built from data collected by Google Street View vans as they match locations with WiFi signals from routers (or at least used to).

此外,我相信谷歌位置服务包含一个数据库,该数据库是根据谷歌街景货车收集的数据构建的,因为它们将位置与来自路由器的 WiFi 信号相匹配(或至少曾经使用过)。

Accessing the database

访问数据库

As for the database (Google Location Services), thisSO question will help you access it.

至于数据库(谷歌定位服务),这个问题将帮助你访问它。

回答by robertc

In Firefox open a new tab and type in the address about:config. Go past the warning message and type geo.wifi.uriinto the filter box, you are now looking at the web service Firefox uses for determining your location.

在 Firefox 中打开一个新选项卡并输入地址about:config。跳过警告消息并geo.wifi.uri在过滤器框中键入内容,您现在正在查看 Firefox 用于确定您的位置的网络服务。

回答by Nobin Thomas

From Firefox's "How does it work":

来自Firefox 的“它是如何工作的”

When you visit a location-aware website, Firefox will ask you if you want to share your location.
If you consent, Firefox gathers information about nearby wireless access points and your computer's IP address. Then Firefox sends this information to the default geolocation service provider, Google Location Services, to get an estimate of your location. That location estimate is then shared with the requesting website.
If you say that you do not consent, Firefox will not do anything.

当您访问位置感知网站时,Firefox 会询问您是否要共享您的位置。
如果您同意,Firefox 会收集有关附近无线接入点和您计算机 IP 地址的信息。然后 Firefox 将此信息发送到默认的地理定位服务提供商 Google 位置服务,以获取您的位置估计值。然后将该位置估计与请求网站共享。
如果您说您不同意,Firefox 不会做任何事情。

and from "How Chrome determines your location":

以及“Chrome 如何确定您的位置”

If you allow Google Chrome to share your location with a site, the browser will send local network information to Google Location Services to get an estimate of your location. The browser can then share your location with the requesting site. You should examine a website's privacy policy before sharing your location with them.

如果您允许 Google Chrome 与某个站点共享您的位置,则浏览器会将本地网络信息发送到 Google 位置服务以估算您的位置。然后浏览器可以与请求站点共享您的位置。在与他们分享您的位置之前,您应该检查网站的隐私政策。

回答by Aram

My guess to the last question in update4 is that supposedly they are updating your location from time to time, based on what device you use. For example if you used only your PC to access the web, and there is no known wifi networks nearby then your location will be determined by IP address, however information about your network will be gathered, later say you connect iPhone or any other device with GPS to your same wifi network, and use GPS on it, google will match those GPS coordinates to your wifi SSID or IP address. So, after then whenever your browser on PC sends a request for geolocation, it will check if the IP and SSID match (and maybe bunch of other things too, like SSID's in neighborhood and so on), and if they match, it will return the location that was previously determined by your GPS equipped device. This is just a guess of course, but it could be so.. also, even if you have never connected any GPS equipped device to your network, but it still determines it accurately, that might be because of the wifi networks in neighborhood, that are already known by google.. that's an awesome work they do, for sure :)

我对 update4 中最后一个问题的猜测是,据说他们会根据您使用的设备不时更新您的位置。例如,如果您仅使用 PC 访问网络,并且附近没有已知的 wifi 网络,那么您的位置将由 IP 地址确定,但是将收集有关您的网络的信息,稍后假设您将 iPhone 或任何其他设备连接到GPS 到您的同一个 wifi 网络,并在其上使用 GPS,谷歌会将这些 GPS 坐标与您的 wifi SSID 或 IP 地址匹配。因此,此后,无论何时您的 PC 上的浏览​​器发送地理定位请求,它都会检查 IP 和 SSID 是否匹配(可能还有其他一些东西,例如附近的 SSID 等),如果匹配,它将返回之前由配备 GPS 的设备确定的位置。

Update:
       Firefox
       Google Chrome

更新:
       火狐
       谷歌浏览器