javascript - 如何通过一次点击链接连续获取位置

标签 javascript php mobile geolocation

我正在尝试通过 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
  }
}

这里是MSDN Docs about Gelocation .

关于javascript - 如何通过一次点击链接连续获取位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57735222/

相关文章:

html - 背景 : fixed no repeat not working on mobile

jQuery .select() 不适用于移动设备

java - 针对用户偏好的phonegap Android 插件

javascript - 将类添加到 div,其中属性值的部分匹配与单独数组中的任何值都不匹配

php - 如何使用 mysql 和 php 选择多行?

php - 使用 knp snappy bundle 生成 pdf - symfony2

html - 使用纯 HTML 切换到移动 View

javascript - 是否可以(并且正确)调用返回数组并直接使用索引键的函数?

php - 通过 post 方法将坐标从 View 传递到 Controller

php - 如何使用 FriendsOfCake Search for CakePHP 3 过滤关联的 HABTM 数据