I am trying to use geolocation API in my app. Luckily I found one that I'd like to use at the MDN website, but when I tried testing for the geolocation object (if it exists in the browser) I got this error:
Server Error
ReferenceError: navigator is not definedThis error happened while generating the page. Any console logs will be displayed in the terminal window.
Source pages/index.js (24:20) @ eval22 | } 23 | > 24 | if('geolocation' in navigator) { | ^ 25 | console.log('It does exist') 26 | } else { 27 | console.log('doesn't exist')
This is the code I tried implementing (from the MDN docs website) :
if('geolocation' in navigator) {
/* geolocation is available */
} else {
/* geolocation IS NOT available */
}
Can you let me know what I'm doing wrong, and how to fix it?