-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
how to know which HEMISPHERE? #32
Comments
@pierroo Hi, I think that's trying to leverage Daylight Savings Time to deduce winter / summer - that might work in a lot of location, but I don't think is a reliable method. Geolocation API is a better approach, but keep in mind some people block that data for security purposes. But you'd be obtaining the latitude navigator.geolocation.getCurrentPosition((position) => {
let lat = position.coords.latitude;
let long = position.coords.longitude;
}); I think positive latitude is Nothern Hemisphere, with negative latitude as Southern Hemisphere. Interesting idea... I might incorporate that but keep in mind it requests permissions like sites that "want to use your current location". If a user blocks that, can't expect too much. |
Ideal if an API provided this, but then probably a separate responsibility. Targeting CJS browser capabilities, I'm unsure about React Native specific aspects in this library - I'd think the browser's locale would probably be telling via Spent a lot of time in hell with Time Zone mappings with massive json datasets, which I'd prefer to avoid here. This is 2k library, 1k gzip - which I had intended for this to be a micro package. All good ideas, though - let me think about it. |
I've had the same question a few days ago and found that currently, only using a third-party API like ipapi.co, you can achieve this with precise (though invasive) information. However, there are a few considerations to keep in mind: privacy, user consent, and terms of service. The easiest way might be to simply ask the user for their location, depending on the end use for your case. It's important to note that the same time zones can exist in both hemispheres. Using Regarding the question, making a fetch request to https://ipapi.co/json/ will provide a response with the keys needed to determine the user's hemisphere. fetch('https://ipapi.co/json/')
.then(response => response.json())
.then(data => {
const latitude = data.latitude;
const isNorth = latitude > 0;
if (isNorth) {
console.log("The user is in the Northern Hemisphere.");
} else {
console.log("The user is in the Southern Hemisphere.");
}
})
.catch(error => {
console.error("Error fetching the location:", error);
}); Due to privacy concerns, I believe this functionality is out of scope for this package. |
Considering how important this parameter is, is there any way to know which Hemisphere the user is from?
Perhaps it's out of scope for this library;
if we forward the iso country code, or the country (from react-native-localize for example), would it be possible to have a mapping function in this library to get the user's hemisphere?
Edit: I have found the following online:
do you think it could do the trick, and perhaps be part of your library?
The text was updated successfully, but these errors were encountered: