I have this type of code in a NextJS component:
const [currentGPS, setCurrentGPS] =
useState({coords:{latitude:0.0,longitude:0.0}})
useEffect(() => {
utl.getGPSLocation(
(v:{coords: {latitude:number; longitude:number;};})=>
setCurrentGPS(v))
}, [])
When using the function below:
function getGPSLocation({callBackFn}:
{callBackFn:
(v:{coords: {latitude:number; longitude:number;};}) => void
}) {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(
(position: {coords: {latitude:number; longitude:number;};}) => {
callBackFn(position)
console.log('(U)position.coords.latitude='+JSON.stringify(position.coords.latitude))
console.log('(U)position.coords.longitude='+JSON.stringify(position.coords.longitude))
});
} else {
console.log("Geolocation is not supported by this browser.");
}
} /* End of getGPSLocation */
I get this error in the Web Developer Tools console of my web browser:
Uncaught TypeError: t is not a function
NextJS 10
page-1aeb39b39d44f814.js:1:332
The message above is due to the line of code:
callBackFn(position)
If I comment out the line, I see what I expect:
(U)position.coords.latitude=25.515932844138406 page-2bc533c4f68ab71b.js:1:339
(U)position.coords.longitude=67.32855152591916 page-2bc533c4f68ab71b.js:1:417
Why am I getting the error? And what is the way to solve it?
I need to have the right syntax to use to pass my function (setCurrentGPS) to getGPSLocation() when calling it.
