navigator geolocation getCurrentPosition not working

天涯浪子 提交于 2020-01-05 09:35:33

问题


I have this html page:

<!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>

Works on:

  • Samsung Galaxy 3 Google Chrome
  • Samsung Galaxy 3 native web browser
  • Chrome Desktop.

Doesnt works on:

  • Samsung Galaxy S2 Chrome
  • Samsung Galaxy S2 native
  • Firefox in desktop

I´ve been reading a lot of questions about this issue, but all of them says sometimes the position is unavailable or may be take a long time to retrieve it, but when I open the android maps app, it shows a perfect location immediately (even if I dont use it for a while)

I know I can use the timeout option to handle the error callback, but thats not a solution for me.

Thanks!


回答1:


It may be due to problems of application permissions

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



来源:https://stackoverflow.com/questions/18980037/navigator-geolocation-getcurrentposition-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!