gpt4 book ai didi

google-chrome - Google Chrome 如何知道我当前的 GPS 位置以及如何在我的代码中使用它?

转载 作者:行者123 更新时间:2023-12-01 10:13:34 25 4
gpt4 key购买 nike

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

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

最佳答案

也可以使用实际的 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);

您好,萨沙

关于google-chrome - Google Chrome 如何知道我当前的 GPS 位置以及如何在我的代码中使用它?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3343562/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com