Geolocation Based on country

Since you only need to know the location at the country level, I’d suggest to use a third party to get the country by IP.
(The solutions that Yisrael suggested require user consent).