Next.js Discord

Discord Forum

GeoLocation error

Unanswered
Naeemgg posted this in #help-forum
Open in Discord
how can we get users lat and long?
this method is not working:
export function getGeolocation() {
    if (navigator.geolocation) {
      navigator.geolocation.getCurrentPosition(
        position => {
          const { latitude, longitude } = position.coords;
          return { latitude, longitude };
        },
        error => console.error('Error getting geolocation:', error)
      );
    } else {
      console.error('Geolocation is not supported by this browser.');
    }
  }

I'm getting error navigator not defined in both client & server components

0 Replies