Navigator.geolocation.GetCurrentPosition throws "Last location provider failed error"

I am trying to create a very basic HTML5 page that captures geolocation, but I get an error.

Here is what I have inside the <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); } 

There is only a button on the page that calls the GetGeo () function.

What I did was delete the .html file on my phone's sdcard. Then I looked at "content: //com.android.htmlfileprovider/sdcard/GetGeo.html" and the page displayed correctly. When I click the button and execute, I get the following error: "The last location provider has been disabled"

I have a couple of questions: 1: Is it wrong to just delete the html file on the SDCard and try to run it there? 2: Is there something basic that I am doing wrong that prevents him from getting geolocation from a mobile browser?

Thanks in advance for your help!

+4
source share
2 answers

I realized this: I had to go into the settings of my mobile browser and check the box "Enable location"

+7
source

It’s also important to enable all location sources on the Android Settings tab. Go to the "Settings" section, click "Location and Security". From here, make sure that the following is verified: (1) Use wireless networks, (2) Use GPS satellites, (3) Help the sensor.

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

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

Source: https://habr.com/ru/post/1344952/


All Articles