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:
Working with application over HTTPs
Various combinations of PositionOptions object passed as third argument to navigator.geolocation.getCurrentPosition.
Downgrading firefox from 61.0.1 to 53.0.3
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();
}
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.
Related Questions
- → How to update data attribute on Ajax complete
- → October CMS - Radio Button Ajax Click Twice in a Row Causes Content to disappear
- → Octobercms Component Unique id (Twig & Javascript)
- → Passing a JS var from AJAX response to Twig
- → Laravel {!! Form::open() !!} doesn't work within AngularJS
- → DropzoneJS & Laravel - Output form validation errors
- → Import statement and Babel
- → Uncaught TypeError: Cannot read property '__SECRET_DOM_DO_NOT_USE_OR_YOU_WILL_BE_FIRED' of undefined
- → React-router: Passing props to children
- → ListView.DataSource looping data for React Native
- → Can't test submit handler in React component
- → React + Flux - How to avoid global variable
- → Webpack, React & Babel, not rendering DOM