Is there an easy way to determine which hemisphere a user is in?

I am working on a project that includes seasonal content, and we are thinking about locating the user to determine what time he is for them. The obvious way to do this is to geo-locate their IP and then capture latitude. > 0 is the northern hemisphere, 0 is the south.

I am happy to go this route - although it seems like a waste to determine the exact IP address for the exact location, just to determine which half of the planet they are on, but I thought I would drop it there if who has any tricks that could shorten the process.

To request headers, things that can be retrieved using JS on the client, all this is quite easy to get - I just don't think it helps.

+6
source share
2 answers

I would first check the client hours - if there is daylight saving time in the client’s calendar, you can determine if it is in the north or south of the equator.

If there is no dst data, you can use geolocation,

or ask the user if he is south of the equator ...

window.whatHemisphere= (function(){ var y= new Date().getFullYear(); if(y.getTimezoneOffset()==undefined) return null; var jan= -(new Date(y, 0, 1, 0, 0, 0, 0).getTimezoneOffset()), jul= -(new Date(y, 6, 1, 0, 0, 0, 0).getTimezoneOffset()), diff= jan-jul; if(diff> 0) return 'N'; if(diff< 0) return 'S' return null; })() 
+2
source

You can use the navigator.geolocation method to avoid any IP service.

+5
source

Source: https://habr.com/ru/post/899661/


All Articles