function setCountryBasedOnGPSLocation() {
  if (navigator.geolocation) {
    navigator.geolocation.getCurrentPosition(
    (position) => {
      const { latitude, longitude } = position.coords;
      fetch(`https://nominatim.openstreetmap.org/reverse?lat=${latitude}&lon=${longitude}&format=jsonv2`)
        .then((response) => response.json())
        .then((data) => {
        const address = data.address;
        const country = address.country;
            const countryElement = document.getElementById("Country");
            if (countryElement) {
              countryElement.value = country;
              console.log(`Country: ${country} updated based on geolocation location`);
            } else {
              console.warn("No element found with ID: Country");
            }
          })
          .catch((error) => console.error("Error fetching country data based on GPS:", error));
      },
      (error) => {
        console.error("Geolocation error:", error.message);
      }
    );
  } else {
    console.error("Geolocation is not supported by this browser.");
  }
}

window.onload = function () {
  setCountryBasedOnLocation();
};