我正在尝试通过 URL 访问获取移动用户位置。使用 PHP $_SERVER 变量我可以获得 ipv4/ipv6 地址,但结果不太准确。
with the one click of user javascript can send a client location. but it's asks for the user permission, it's fine. but after the one click, expecting to get a location continuously, even the browser is not active
最佳答案
您可以在起始页面的 PWA 中调用以下代码。这样,每次用户通过您提供的链接打开它时,应用程序都会获取她/他的位置:
function getLocation() {
// Check if the current device support geoLocation
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function(pos) {
console.log("Latitude: " + pos.coords.latitude +
"Longitude: " + pos.coords.longitude);
});
} else {
// Geolocation is not supported by the
}
}
关于javascript - 如何通过一次点击链接连续获取位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57735222/