0
I’m trying to use the navigator.geolocation.getCurrentPosition
and the navigator.geolocation.watchPosition
in a PWA project made with Quasar.
It is working very well in Browser and Cordova (Android), but an error occurs when publishing in 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)
, I mean, it’s not a problem with my key to the API do Google
.
In any case, follow 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 make the direct call from Restman, he returns the location smoothly.:
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
}
Not I’m sure, but I think it’s a bug in version 58.0.3029.110 of Chromium (currently the version that Electron uses), this bug was fixed I believe in version 61, so only when they update Chromium to a newer version than 61 to fix the problem.
– Guilherme Nascimento