【问题标题】:How can I block fake location in the web? [duplicate]如何阻止网络中的虚假位置? [复制]
【发布时间】:2019-05-07 05:14:12
【问题描述】:

我使用 javascript 获取用户的位置。如何防止虚假位置? 这是我的代码:

if (navigator.geolocation) {
    navigator.geolocation.getCurrentPosition(showPosition, showError);
}

它的showPosition函数:

function showPosition() {
    Latitude  = position.coords.latitude;
    Longitude = position.coords.longitude;
}

【问题讨论】:

    标签: javascript


    【解决方案1】:

    您无法检测到用户是否正在使用模拟。

    一种方法是使用用户的 IP 地址并获取位置,但它可能不准确。 您可能需要检查以下问题:

    how to detect when user is using mock location chrome browser

    【讨论】:

    • 当您找到解决问题的答案时,不要发布指向它的链接,而是使用内置功能“投票/标记以关闭为重复项”。如果你没有足够的代表。要做到这一点,移动一个,其他有的人会这样做。
    • 好的,下次我会这样做的。
    【解决方案2】:

    您无法真正防止位置欺骗,但您可以检查 GPS 位置是否与 IP 的区域匹配。

    我建议您使用公共 API,因为这很容易。

    //This only works if for http
    fetch('http://www.geoplugin.net/json.gp')
    .then((resp) => {
      if(!resp.ok) {
        console.warn('Cannot fetch location data')
        return
      }
      return resp.json()
    })
    .then((data) => {
      //Check if the location matches with a margin of one degree
      if(Math.abs(Latitude - data.geoplugin_latitude) < 1 && Math.abs(Longitude - data.geoplugin_longitude) < 1) {
        console.log("Location is valid")
      } else {
        console.warn("Location is probably fake")
      }
    })
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-07-22
      • 1970-01-01
      • 2014-09-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多