I'm trying to use navigator.geolocation.getCurrentPosition
and navigator.geolocation.watchPosition
in a PWA project made with Quasar.
It works very well in Browser and Cordova (Android), but an error occurs when publishing on Electron.:
PositionError {
code: 2,
message: "Network location provider at 'https://www.googleapis.com/' : Returned error code 400."
}
Note that it is an Error 400 (Bad Request)
and not 403 (Forbidden)
, that is, it is not a problem with my API do Google
key.
In any case, it follows the excerpt from the file main.js
where the API is being configured.:
'use strict'
const
electron = require('electron'),
path = require('path'),
config = require('../config/electron'),
app = electron.app,
BrowserWindow = electron.BrowserWindow
let mainWindow
function createWindow () {
mainWindow = new BrowserWindow({
...
})
...
mainWindow.on('closed', () => {
mainWindow = null
})
}
process.env.GOOGLE_API_KEY = 'blablabla'
process.env.GOOGLE_DEFAULT_CLIENT_ID = 'blablabla.apps.googleusercontent.com'
process.env.GOOGLE_DEFAULT_CLIENT_SECRET = 'blablabla'
app.on('ready', createWindow)
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit()
}
})
app.on('activate', () => {
if (mainWindow === null) {
createWindow()
}
})
When I call the RestMan direct call, it returns the location without problems.
curl -H "Content-Type: application/json" -X POST -d '{}' https://www.googleapis.com/geolocation/v1/geolocate?key=blablabla
{
"location": {
"lat": -x.fffffff,
"lng": -y.fffffff
},
"accuracy": fff
}