5

While I was researching in order to answer a question on Stack Oveflow en español, I decided to try the code on https://developer.mozilla.org/docs/Web/API/Geolocation/getCurrentPosition1.

But I got the following error

Warning: ERROR(1): User denied Geolocation

I think that Google Chrome is considering the stack snippet as insecure. See Geolocation API Removed from Unsecured Origins in Chrome 50. Is there something that as end-user I could do to make this work?

1 The referred link was the original source of the referenced code. If you need the English version see https://developer.mozilla.org/en/docs/Web/API/Geolocation/getCurrentPosition but bear in mind that the Mozilla Developer Network docs are edited by the community and some language versions are not direct translations of another.

var options = {
  enableHighAccuracy: true,
  timeout: 5000,
  maximumAge: 0
};

function success(pos) {
  var crd = pos.coords;

  console.log('Your current position is:');
  console.log('Latitude : ' + crd.latitude);
  console.log('Longitude: ' + crd.longitude);
  console.log('More or less ' + crd.accuracy + ' meters.');
};

function error(err) {
  console.warn('ERROR(' + err.code + '): ' + err.message);
};

navigator.geolocation.getCurrentPosition(success, error, options);

Related posts

9
  • Shouldn't that rather go to Meta Stack Overflow? Jun 24, 2017 at 19:39
  • The stack snippet feature is available on several sites of the network, not only on Stack Overflow, by the other hand here we have a tag about stack snippets :)
    – Rubén
    Jun 24, 2017 at 19:41
  • 2
    @πάνταῥεῖ it can live here.
    – rene
    Jun 24, 2017 at 19:41
  • @Shadow I think that references to the source of the code I took should not be edited.
    – Rubén
    Jun 24, 2017 at 21:53
  • Maybe you could edit the link on the note, but not the reference to the original source.
    – Rubén
    Jun 24, 2017 at 21:54
  • @Rubén yes they should. On this site we should use only English, not Spanish, since most people who browse the site do not understand Spanish. If you want to link to Spanish sites, do it on the per-site meta of Spanish SE sites. I did not change any of the code, just linked to the generic page, not its Spanish version. Jun 24, 2017 at 21:55
  • All the required info about this issue is in English. I also included a link to the English version.
    – Rubén
    Jun 24, 2017 at 21:56
  • Sorry, I really don't get you. I checked now twice. The code is the same in both versions, one just use Spanish to explain and the other English. I don't see what is your problem then. Jun 24, 2017 at 21:58
  • Good to know that you take the time to check that the code is the same in both versions. Not on all MDN docs occurs that, by the other hand, I don't see how that edit make the post clearer.
    – Rubén
    Jun 24, 2017 at 22:03

1 Answer 1

3

My question on Stack Overflow en español got an answer. The most relevant part is that Stack Snippet is blocking the Geolocation API due to the lack of allow-same-origin flag on the sandbox attribute of the iframe used to embed Stack Snippets.

As end-user as a workaround we could add the flag manually or by writing a command on the browser console or to use another service like JSFiddle.

IMHO, a feature request should be made.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .