开发者

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

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 th开发者_如何学Cere 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!


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


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" />
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜