I'm using electron and angular 7 for a desktop app.

Trying to use geolocation I got error code:2 but not more detail of error.

I'm using a valid API-key assigned in process.env.GOOGLE_API_KEY

Here is the code example, the only way I manage it to work was simulating my position via developer tools.

 navigator.geolocation.getCurrentPosition((pos) => console.log(pos), (err) => console.log(err));

My response is a PositionError object with:

code: 2
message: ""

If i override my position via dev tools, I get a position object with the simulated coords.

Version in package.json

  • "electron": "3.0.10",
  • "electron-builder": "20.36.2",


  • Not sure, but it may be returning the 'last' known location. If there weren't a last location, will return null. – kmansoor Apr 11 at 20:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.