navigator.geolocation.GetCurrentPosition throws “The last location provider was disabled” error

依然范特西╮ 提交于 2019-12-10 07:46:39

问题


I am trying to create a very basic HTML5 page that grabs the geolocation, but I'm getting an error.

Here's what I have inside my 'script' tags:

 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);
    }

The page just has a button on it, that calls the GetGeo() function.

What I did is dropped the .html file onto the SDCard of my phone. Then, I browsed to "content://com.android.htmlfileprovider/sdcard/GetGeo.html" and the page shows up correctly. When I click the button and execute, I get the following error: "The last location provider was disabled"

I have a couple questions: 1: Is it wrong to just drop the html file on the SDCard and try to run it there? 2: Is there something basic that I'm doing wrong that is not letting it get the geolocation from the mobile browser?

Thanks in advance for any help!


回答1:


I figured this out: I needed to go into the setting of my mobile browser and check 'Enable Location'




回答2:


It is also important to enable all the location sources from the Android Settings tab. Go to Settings, click on Location and Security. From here, make sure that the following are checked: (1) Use wireless networks, (2) Use GPS satellites, (3) Use sensor aiding.

Also make sure that the following permission is enabled in the manifest:

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />


来源:https://stackoverflow.com/questions/5407973/navigator-geolocation-getcurrentposition-throws-the-last-location-provider-was

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