html navigator "User denied Geolocation"

Viewed 62474

I have an issue with window.navigator, I'm getting error code 1, "User denied Geolocation" whenever I run the following code as a local html file:

navigator.geolocation.getCurrentPosition(function(position) {
        console.log(position);
    }, function(positionError) {
        console.log(positionError);
    });

The output is coming from the error function, positionError contains:

code: 1
message: "User denied Geolocation"

This does not happen if the containing html is served from some server.

Is this expected? Is there some way to use navigator from a local html? I am trying to write some mobile app, but am also trying to avoid network whenever possible.

thanks.

3 Answers

Just click on the left side of the url on the little 'i' symbol:- (Refer the image below)

info symbol illustration

Then check if the location is 'block'. Change it to 'allow' and then reload the page.

Hope this helps.

Related