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

ask user to get current location in mobile browser

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

我在网上找到了这段代码,但它在手机浏览器中不起作用

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) { /* ... */ });

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

如果您的浏览器不在此列表中,则表示您无法使用地理定位:

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

如我们所见,您需要使用:

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