草庐IT

android - navigator.geolocation.GetCurrentPosition 抛出 "The last location provider was disabled"错误

coder 2023-12-19 原文

我正在尝试创建一个非常基本的 HTML5 页面来获取地理位置,但出现错误。

这是我的“脚本”标签中的内容:

 function GetGeo() {
        if (!navigator.geolocation) {
            alert("Could not find geolocation");
        }
        else {
            navigator.geolocation.getCurrentPosition(showMap, function (error) { alert("error encountered: " + error.message ); });
        }
    }

    function showMap(position) {
        window.alert(position.coords.latitude + ", " + position.coords.longitude);
    }

页面上只有一个按钮,调用 GetGeo() 函数。

我所做的是将 .html 文件放到手机的 SDCard 上。然后,我浏览到“content://com.android.htmlfileprovider/sdcard/GetGeo.html”,页面正确显示。当我单击按钮并执行时,出现以下错误:“最后一个位置提供程序已被禁用”

我有几个问题: 1:直接把html文件放到SDCard上,然后尝试在那里运行是不是错了? 2:有没有什么基本的我做错了,没有让它从移动浏览器获取地理定位?

在此先感谢您的帮助!

最佳答案

我想通了:我需要进入我的移动浏览器的设置并选中“启用位置”

关于android - navigator.geolocation.GetCurrentPosition 抛出 "The last location provider was disabled"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5407973/

有关android - navigator.geolocation.GetCurrentPosition 抛出 "The last location provider was disabled"错误的更多相关文章

随机推荐