【问题标题】:How Google Chrome knows my current GPS location and how to use it in my code?Google Chrome 如何知道我当前的 GPS 位置以及如何在我的代码中使用它?
【发布时间】:2011-10-28 03:24:56
【问题描述】:

今天我意识到某些页面可以使用谷歌浏览器以非常精确的方式定位我(我使用没有内置 gps 的笔记本电脑),我知道使用我的 IP 你可以找到我,但不是这样的 presision .现在在google maps 中,您会在使用google chrome 定位您的黄人(街景)上方看到一个按钮。

这是如何工作的?有一个 API 可以使用它吗?

【问题讨论】:

  • 刚试了一下,它以大约 20 米的精度定位我!令人印象深刻!

标签: google-chrome gps


【解决方案1】:

也可以使用实际的 HTML 5 地理定位功能(仅当您的浏览器支持时):

if (navigator.geolocation) {
  navigator.geolocation.getCurrentPosition(success, error);
} else {
  alert("Not Supported!");
}

function success(position) {
  console.log(position.coords.latitude);
  console.log(position.coords.longitude);
}

function error(msg) {
  console.log(typeof msg == 'string' ? msg : "error");
}

var watchId = navigator.geolocation.watchPosition(function(position) {  
  console.log(position.coords.latitude);
  console.log(position.coords.longitude);
});

navigator.geolocation.clearWatch(watchId);

您好, 萨沙

【讨论】:

    【解决方案2】:

    查看help page

    Google 位置服务用于估计您的位置的本地网络信息包括有关可见 WiFi 接入点的信息,包括其信号强度;有关您本地路由器的信息;您计算机的 IP 地址。 Google 位置服务的准确性和覆盖范围因位置而异。

    【讨论】:

      【解决方案3】:

      以下是 Firefox 代码的链接,可让您访问 Google 定位服务: http://mxr.mozilla.org/mozilla1.9.1/source/dom/src/geolocation/NetworkGeolocationProvider.js

      享受吧!

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2020-01-11
        • 2011-04-07
        • 2019-12-23
        • 2021-05-08
        • 1970-01-01
        • 1970-01-01
        • 2020-08-01
        • 1970-01-01
        相关资源
        最近更新 更多