batoulapps / adhan-kotlin

High precision Islamic prayer time library for Java
MIT License
161 stars 47 forks source link

Calculation based on altitude #12

Open digitalummah opened 4 years ago

digitalummah commented 4 years ago

Is altitude / elevation a parameter in calculating the prayer times?

z3bi commented 4 years ago

This library does not use altitude for calculations. Altitude is tricky as it only has an effect when the altitude of the observer differs from the altitude of the horizon, for example being on mountain peak. But if the city you live in has a high altitude in all locations it has no effect.

Here is a good explanation of the apparent effects of altitude on sunrise https://astronomy.stackexchange.com/questions/24632/how-do-i-adjust-the-sunrise-equation-to-account-for-elevation

I think knowing the difference in altitude between the observer and the horizon is going to be extremely difficult for any application to know.

digitalummah commented 4 years ago

This makes sense - thanks for the swift response!

Abu-Abdullah commented 4 years ago

Alsalam Alikom,

@z3bi , i beleive it might be good to have Altitude as an option to adjust the calculation. people who is in high rise towers differes in maghrib and fajr by 2 minites. for such reason, i knew that Awqaf in some cities start put their calculations to have Altitude of around 200 feets (not sure from sea level, elevation or from city land level). this result in maybe few seconds (or a minute) from the normal caluclation.

another point is the mountain as you mentioned. third one is when you are in airplane. it might be good option for those who enable your library in their phone app to get the altitude from their phone GPS.

z3bi commented 4 years ago

@Abu-Abdullah My biggest concern with this is if developers always supply the altitude to the library regardless of the situation. This can cause a big issue in cities like Denver. Even though Denver is at an altitude of 5,000 ft, that altitude is consistent in the whole city so it doesn't affect sunrise/sunset times.

One feature the library needs is a function that recommends calculation parameters given a set of coordinates and city and country. Perhaps there's a good way for that function to identify true needs for altitude adjustment. I'm open to suggestions on how to make that clear in the design of the library's interface.

Abu-Abdullah commented 4 years ago

i would agree on your point but still this is a library not the final app, there is a responsbility on the developer to understand this feature and develop wht is suitable to make sure that this parameter is correct.

i beleive any suggestion will end up with the need to have internet connection to check the altitude of the city compared to the sea level. i have the following code to get the Altitude:

        // Only for US !!!!
    private double getAltitude(Double longitude, Double latitude)
    {
        double result = Double.NaN;
        final String url = "https://nationalmap.gov/epqs/"
                + "pqs.php?x=" + longitude
                + "&y=" + latitude
                + "&units=Feet&output=xml";

        // Require API key and an account for google maps and 25000 hits limit per day
        String url_google = "https://maps.googleapis.com/maps/api/elevation/"
                + "xml?locations=" + latitude
                + "," + longitude
                + "&sensor=true";

        try
        {
            final DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
            final DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
            final Document doc = docBuilder.parse(url);

            // normalize text representation
            doc.getDocumentElement().normalize();

            // The results are contained in a single <double> node
            final NodeList listOfDoubles = doc.getElementsByTagName("Elevation");

            if (listOfDoubles.getLength() > 0)
            {
                Node elevationNode = listOfDoubles.item(0);
                Element elevationElement = (Element) elevationNode;
                return Double.parseDouble(elevationElement.getFirstChild().getNodeValue());
            }
        }
        catch (IOException | SAXException | ParserConfigurationException e)
        {
            e.printStackTrace();
        }
        return result;
    }
Abu-Abdullah commented 4 years ago

this is really an issue in a city like dubai: https://www.khaleejtimes.com/ramadan-2019/late-iftar-for-burj-khalifa-dubai-skyscraper-residents

z3bi commented 4 years ago

I would probably not add an external API dependency. Perhaps in the example app we could show an external API being used to get the correct values.

Abu-Abdullah commented 4 years ago

ok, i meant we just need to understand how to use the api to take into account the altitude variable (not to include external API).

getting the altitude is the responsibility of the developer. even letting the end user himself adjust this value is one way of doing it (with good explanation).

getting an example is more than enough (with thanks)

i believe we need to understand what is the altitude that affects the calculation:

z3bi commented 4 years ago

Yeah and in fact we can be more precise by adjusting sunrise and sunset differently by asking for:

This could provide additional accuracy for people living at the base of a mountain range.

z3bi commented 4 years ago

Re-opening this issue as we find a way to offer this functionality in a way that makes it clear how the feature is meant to work and what the limitations are.

mubasherusman commented 1 year ago

Has this feature been included in the library, or has any guide been added?