admin管理员组

文章数量:1313252

When I try to get the current position

navigator.geolocation.getCurrentPosition(handleCoordinates, handleError, {timeout:10000})

it returns

"Network location provider at '/' : Returned error code 400."

Can somebody suggest any possible ways?

When I try to get the current position

navigator.geolocation.getCurrentPosition(handleCoordinates, handleError, {timeout:10000})

it returns

"Network location provider at 'https://www.googleapis./' : Returned error code 400."

Can somebody suggest any possible ways?

Share Improve this question edited Dec 23, 2017 at 21:49 Daniel Puiu 9616 gold badges21 silver badges29 bronze badges asked Dec 23, 2017 at 20:34 VitoVito 3301 gold badge3 silver badges11 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 6

You should configure correct google api key to request google related services in chromium.

https://github./electron/electron/blob/master/docs/api/environment-variables.md#google_api_key

https://github./electron/electron/issues/9420

Initializing Google Api Key In Main JS file :

app.whenReady().then(() => {
  process.env.GOOGLE_API_KEY = 'AI.....'
  createWindow()

  app.on('activate', () => {
    if (BrowserWindow.getAllWindows().length === 0) {
      createWindow()
    }
  })
})

and Calling below method in preload js :

 if (navigator.geolocation) {
    console.log('with in if block');
   navigator.geolocation.getCurrentPosition((position) => {
      console.log("Latitude : " + position.coords.latitude);
    } ,(err ) =>{
      console.log("getting error : " + err.message);
    } , {timeout:10000})

  } else { 
    console.log('with in else block');
  }

  //enter code here: "User has not allowed access to system location."

本文标签: javascriptHow to getCurrentPosition via navigatorgeolocation in Electron appStack Overflow