Chrome 如何知道我的地理位置?
Chrome 似乎能够非常准确地检测我的位置。它是如何做到的?你能指点我源代码吗?
Chrome seems to be very accurate in detecting my location. How does it do it? Can you point me to the source code?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
可以根据以下内容计算地理位置:
请参阅 W3C 地理定位 API 和 Google Gears API(Chrome 的/W3C 地理定位 API 所基于的)。
Chromium 的地理定位源代码可以在线查看。
Geolocation can be calculated based on:
See the W3C Geolocaton API and Google Gears API (which Chrome's/W3C Geolocation API is based on).
Chromium's geolocation source code can be viewed online.
您可以使用设备上可用的不同服务和硬件来获取您的位置。最常见的是:GPS、wifi 信息、手机信号塔。另外,还有 IP 查找,但这不是很准确,并且不涉及您设备上的任何特殊内容。
在您的情况下,很可能使用了有关您的 wifi 网络的信息。有巨大的数据库将 wifi 网络连接到某个位置,这些数据库是由带有 GPS 和 GPS 的汽车创建的。 Wifi(例如谷歌街景汽车)。从您的计算机到服务器的传输是根据 W3C Geolocation API 规范完成的,它是 HTML5 的一部分。
Chrome 的源代码?
这里是一个开始的入口点。或者,如果您更喜欢老式文件浏览器:http://src。 chromium.org/svn/trunk/src/chrome/browser/geolocation/
通过 wifi 进行本地化的实现文件:
Your location can be obtain using different services and hardware available on your device. The most common ones are: GPS, wifi information, cell towers. Alternatively there is also IP lookup, however this is not very accurate and does not involve anything special on your device.
In your case most likely information about your wifi network was used. There are huge databases which connect wifi networks to a location, created by cars with GPS & Wifi (e.g. Google Street View cars). The transmission from your computer to the server is done according to W3C Geolocation API Specs, which is part of HTML5.
Chrome Source for this?
Here is a entry point to start off from. Or if you prefer the old fashioned file browser: http://src.chromium.org/svn/trunk/src/chrome/browser/geolocation/
Implementation files for localization via wifi:
他们会考虑几件事:
->您所在位置的无线网络的唯一标识符 (SSID) 和信号强度。
-> IP地址(您的公共IP地址)
-> GPS(如果有)
->移动网络位置数据(如果有)
They look at several things:
-> The unique identifiers (SSID) of wireless networks at your location and signal strengths.
-> IP address (your public IP address)
-> GPS (if available)
-> Mobile network location data (if available)
电脑上的浏览器没有 GPS,但它有一个外部 IP 地址(通常是路由器的外部 IP 地址)。如果同一路由器后面的其他组件有 GPS - 这会将位置固定到该 IP 地址,并通过位置服务将此位置附加到浏览器。
a browser on a pc does not have a gps, however it has an external ip address (usually the router's external ip address). if other components behind the same router has a gps - this pins location to that ip address and via location services attaches this location to the browser.
我认为他们使用您的 IP 地址和 地理定位 服务,例如 http://www.ip2location.com/ 或(更有可能)他们自己的 地理位置数据库/service)
I think they use your IP address and a geolocation service like http://www.ip2location.com/ or (more likely) their own geolocation database/service)
最近我从事 HTML 5 地理位置分配工作。所有现代浏览器(IE9、Safari、FF、Opera)均支持它。
但当我使用 Chrome 时,它不被支持。我花了几个小时来解决这个问题。
最后我找到了一个解决方案:
Chrome中的地理位置默认是关闭的。要激活它,用户必须转到 Chrome 快捷方式并将
--enable-geolocation
添加到“快捷方式”选项卡下目标行的末尾。Recently i worked on HTML 5 Geo-location assignment. Its supported in all modern browsers (IE9, Safari, FF, Opera).
But when I came to Chrome its not supported. I spent several hours in fixing this.
Finally I found a a solution:
The geolocation in Chrome is turned off by default. To activate it, users must go to their Chrome shortcut and add
--enable-geolocation
to the end of the target line, under the Shortcut tab.