Reputation: 12909
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!
Upvotes: 4
Views: 13216
Reputation: 24892
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" />
Upvotes: 3
Reputation: 12909
I figured this out: I needed to go into the setting of my mobile browser and check 'Enable Location'
Upvotes: 7