导航器地理位置获取当前位置不起作用

navigator geolocation getCurrentPosition not working

本文关键字:位置 不起作用 获取 地理位置 导航      更新时间:2023-09-26

我有这个html页面:

<!DOCTYPE html>
<html>
<head>
    <title>Geolocation test</title>
</head>
<body>
    <script type="text/javascript">
        navigator.geolocation.getCurrentPosition(function (position) {
            alert(position.coords.latitude + ',' + position.coords.longitude);
        }, function (error) {
            alert(error.code);
        }, {enableHighAccuracy: true, maximumAge: 0});
    </script>
</body>

适用于:

  • 三星银河 3 谷歌浏览器
  • 三星银河3原生网络浏览器
  • 铬桌面。

不适用于:

  • 三星银河S2铬
  • 三星银河S2原生
  • 桌面版中的火狐浏览器

我一直在阅读很多关于这个问题的问题,但他们都说有时该位置不可用或可能需要很长时间才能检索它,但是当我打开 android 地图应用程序时,它会立即显示一个完美的位置(即使我一段时间不使用它)

我知道我可以使用超时选项来处理错误回调,但这对我来说不是解决方案。

谢谢!

可能是由于应用程序权限问题

https://support.google.com/chrome/answer/142065?hl=en