B4A Library Astro library

The library provides the times of Sunrise, Sunset, Moon rise and Moon set, according to place and date.
It also provides the phase of the moon (equivalent to the day of the moon month).
The Sunrise and Sunset times vary according to the value of Zenith angle.
The following conventions are in use:
Official – 90.8333 (90° 50’)
Civil - 96°
Nautical - 102°
Astronomical - 108°
The values can be used by their names.
The library use the Official value as default, and it can be changed using the method Zenith.

No demo program as it is very simple to use.
Please report problems.

Edit: Version 1.1 corrected the following as per alfcen comments:
- no_rise or no_set time are returned as "--:--"
- sun rise and set times are within the 24 hours.

Edit: the files are updated to ver. 1.2 with additional methods which provide data about the sun and the moon, all by our astronomy expert alfcen:sign0188:
Edit: Ver 1.21 correction of rounding problem.
Edit: Ver 1.22 bug correction in sun + format change.
Edit: ver 1.23 bug correction in moon phase.
Edit: ver 1.4 added a method to calculate sun's position (azimuth and elevation).
 

Attachments

  • Astro 1.4.zip
    17.5 KB · Views: 627
Last edited:

RUNO

Active Member
Licensed User
Longtime User
Hi all , this library for moon only or moon and sun.
I used it but values does not apply to reality .
 

derez

Expert
Licensed User
Longtime User
It is written in the first post:
The library provides the times of Sunrise, Sunset, Moon rise and Moon set, according to place and date.
It also provides the phase of the moon (equivalent to the day of the moon month).
If you have problems - show your code and we'll help.
 

RUNO

Active Member
Licensed User
Longtime User
Thank you derez
I used example from forum but values not correct with my location. .
 

RUNO

Active Member
Licensed User
Longtime User
Hi
I used astrolib demo with changes location value but old results are still, can you help me ?
 

derez

Expert
Licensed User
Longtime User
I am willing to help you but I can't without seeing the code and values you use to get the results.
 

Del

Member
Licensed User
Longtime User
Derez

This is a great library and very useful.

However note that you get :-
java.text.ParseException: Unparseable date: "01/01/1900" (at offset 2)
if you have previously set DateTime.DateFormat to "HH:mm"

Obvious really but confusing !

Regards

Del
 

derez

Expert
Licensed User
Longtime User
if you have previously set DateTime.DateFormat to "HH:mm"
I'm not sure I get the comment. What you show is time format, not date format.
 

RUNO

Active Member
Licensed User
Longtime User
Derez
I used this library , but need some value like lat ,lon from my location.
If I used GPS ,how I get this value?
How I get my city from app ? any library to do that.
I need answers for this questions , please.
 

RUNO

Active Member
Licensed User
Longtime User
I used before in my app to determine location but didn't give me value for Lat or Lon .
after that I put my location value in code not GPS .
 

RosarioAR

Member
Licensed User
Longtime User
Hi, i have tried the lib with the next code:
B4X:
Dim sunA As Astro
Dim result() As String
   
result=sunA.Sun(26,6,2016,32,-60,-3)
Log(result(0))
Log(result(1))
The result obtained is:
SunRise= 05:56
SunSet= 20:10

I am in Argentine (Lat=32, Long=-60, DST=-3), and today the correct Sunrise/Sunset is 08:06/18:05 aprox.

What am I doing wrong?

Thanks
Regards
 

derez

Expert
Licensed User
Longtime User
The Lat should also be negative -32 since you are in southern latitude.
I get 08:01 and 18:05
 
Last edited:

Emerito

Active Member
Licensed User
Longtime User
The library provides the times of Sunrise, Sunset, Moon rise and Moon set, according to place and date.
It also provides the phase of the moon (equivalent to the day of the moon month).
The Sunrise and Sunset times vary according to the value of Zenith angle.
The following conventions are in use:
Official – 90.8333 (90° 50’)
Civil - 96°
Nautical - 102°
Astronomical - 108°
The values can be used by their names.
The library use the Official value as default, and it can be changed using the method Zenith.

No demo program as it is very simple to use.
Please report problems.

Edit: Version 1.1 corrected the following as per alfcen comments:
- no_rise or no_set time are returned as "--:--"
- sun rise and set times are within the 24 hours.

Edit: the files are updated to ver. 1.2 with additional methods which provide data about the sun and the moon, all by our astronomy expert alfcen:sign0188:
Edit: Ver 1.21 correction of rounding problem.
Edit: Ver 1.22 bug correction in sun + format change.
Edit: ver 1.23 bug correction in moon phase.
Edit: Ver 1.3 - added SunPosition method to find Azimuth and Elevation of the sun.

Derez, can this library be used freely?
 

derez

Expert
Licensed User
Longtime User
The Sunposition regrettably does not seem to report back the correct Sun Azimuth and Elevation.
Others have experienced this too: https://www.b4x.com/android/forum/threads/calculating-solar-azimuth-solved.73665/#post-467905
Is there a bug in the code or does it have to do with the time parameter (I use datetime.now)? I have used:
B4X:
Dim AzimuthAstro() As Double        'Under Globals; Two parameters:  Azimuth and Elevatie

AzimuthAstro=ast.SunPosition(52.10,4.50,DateTime.now)
'Added to Derez's example:
m = m & "Sun Azimuth: " & Round2(AzimuthAstro(0),1) & CRLF
m = m & "Sun Elevation: " & Round2(AzimuthAstro(1),1) & CRLF
I have checked and also found wrong results (in elevation, azimuth looks ok). I'll check.
 
Top