要求用户在移动浏览器中获取当前位置

时间:2019-06-12 07:00:53

标签: javascript jquery html mobile-chrome

我有一个指南针网络应用程序,它指向客户端商店的位置,并且我想获得用户的地理位置许可,以便可以使用这两个位置。

我在互联网上找到了此代码,但在移动浏览器中无法使用

navigator.permissions.query({ name: 'geolocation' }).then(function(result) {
    /* result.status = "prompt" */
});


navigator.geolocation.getCurrentPosition(function(result) { /* ... */  })

navigator.permissions.query({ name: 'geolocation' }).then(function(result) {
    /* result.status = "granted" */
});

navigator.permissions.query({ name: 'push', userVisibleOnly:true }).then(function(result) { /* ... */ });

1 个答案:

答案 0 :(得分:0)

您的浏览器必须支持此功能

如果此列表中不存在您的浏览器,则意味着您不能使用地理位置:

https://caniuse.com/#feat=geolocation

我们看到,您需要使用:

  • Opera Mobile
  • Chrome for Android
  • Firefox for Android
  • IE Mobile
  • UC Browser for Android