Ad

Callbacks For Navigator.geolocation.getCurrentPosition Are Not Firing In Firefox

I have the function inside React Component which is responsible for getting user's position.

    export default class SomeComponent extends React.Component<SomeProps, SomeState> {
    constructor(props: any) {
    super(props)
    //initializing state here...
    }
      componentDidMount() {
        this.getCurrentPosition()
      }

    getPosition = () => {
    console.log('get current position') //it's firing
      navigator.geolocation.getCurrentPosition((position: Position) => {
        console.log('pos', position) // not firing in any case
        //do stuff here..
      },
        (error: any) => {
          console.log(error) //not firing in any case
            //do stuff here..
        })
    }
}

My problem is that this approach works perfectly fine in Chrome/Edge, but in Firefox none of the navigator.geolocation.getCurrentPosition callbacks are firing. OS: MS Windows 10. Firefox: 61.0.1

What i already tried to do:

  1. Working with application over HTTPs

  2. Various combinations of PositionOptions object passed as third argument to navigator.geolocation.getCurrentPosition.

  3. Downgrading firefox from 61.0.1 to 53.0.3

  4. Fiddling with about:config geo options. For instance, changing the geo.wifi.uri from https://www.googleapis.com/geolocation/v1/geolocate?key=%GOOGLE_API_KEY% to https://location.services.mozilla.com/v1/geolocate?key=%MOZILLA_API_KEY%

    Current geo options:
    geo.enabled: true
    geo.provider.ms-windows-location: false
    geo.wifi.uri: https://www.googleapis.com/geolocation/v1/geolocate?key=%GOOGLE_API_KEY%
    geo.wifi.xhr.timeout: 60000

5 Reassembling getPosition in plain javascript way and calling it from tsx component.

 // navigator.js

    function succ(pos){
       console.log('pos', pos)
    }
    function err(err){
       console.log('err', err)
    }
    export default function Nav(){
       console.log('nav')
       navigator.geolocation.getCurrentPosition(succ, err);
    }

    //SomeComponent.tsx
    import Nav from '../containers/navigator.js'
      componentDidMount() {
        Nav();
      }
Ad

Answer

This issue was caused by simultaneous use of react-geolocated lib and navigator.geolocation.getCurrentPosition(). Callback didn't fired probably because firefox thinks that geolocation already resolved. Commenting out react-geolocated lib usage helped.

Ad
source: stackoverflow.com
Ad