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

前端 未结 2 1367
醉梦人生
醉梦人生 2020-12-19 10:16

I\'m working on a project which includes seasonal content, and we\'re thinking of determining the user\'s location to work out what season it is for them. The obvious way of

相关标签:
2条回答
  • 2020-12-19 10:35

    You could use the navigator.geolocation method to avoid any sort of IP service.

    0 讨论(0)
  • 2020-12-19 10:43

    I'd first check the client's clock- if daylight savings exists in the client's calendar, you can tell if he is north or south of the equator.

    if there is no dst information, 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;
    })()
    
    0 讨论(0)
提交回复
热议问题