Astronomical calculations in JavaScript.
These tiles were generated using the astronomy-svg library.
👉 Check out the live demo here
AstronomyJSThe main class to interact with the library.
initialize(latitude, longitude)
AstronomyJS instance with the given coordinates on Earth.latitude (number): Latitude in degrees.longitude (number): Longitude in degrees.AstronomyJS instance.const astronomy = AstronomyJS.initialize(52.52, 13.405);
// Returns: AstronomyJS { ... }
setDate(date)
date (Date object): The new simulation date.astronomy.setDate(new Date("2024-03-20T12:00:00Z"));
getDate()
Date object.const date = astronomy.getDate();
// Returns: 2024-03-20T12:00:00.000Z
setJulianDate(julianDate)
julianDate (number): The new Julian Date.astronomy.setJulianDate(2460389.5);
getJulianDate()
const julianDate = astronomy.getJulianDate();
// Returns: 2460389.5
setLocation(objectName, latitude, longitude, elevation)
objectName (string): Name of the solar system body (e.g., “Earth”).latitude (number): Latitude in degrees.longitude (number): Longitude in degrees.elevation (number): Elevation from surface in meters.astronomy.setLocation("Earth", 48.8566, 2.3522, 35);
getAltitudeAzimuthCoordinatesForObject(objectName, [referenceDate])
objectName (string): Name of the object (e.g., “Sun”, “Moon”, “Mars”).referenceDate (Date, optional): Overrides the instance date.azimuth, altitude, and distance.const coordinates = astronomy.getAltitudeAzimuthCoordinatesForObject("Sun");
/*
Returns:
{
"azimuth": 185.23,
"altitude": 42.15,
"distance": 0.9958,
"observerLocation": { ... }
}
*/
getRightAscensionDeclinationCoordinatesForObject(objectName, [referenceDate])
objectName (string): Name of the object (e.g., “Sun”).referenceDate (Date, optional): Overrides the instance date.rightAscension, declination, and distance.const coordinates = astronomy.getRightAscensionDeclinationCoordinatesForObject("Sun");
/*
Returns:
{
"rightAscension": 358.12,
"declination": -1.25,
"distance": 0.9958,
"observerLocation": { ... }
}
*/
getHourAngleDeclinationCoordinatesForObject(objectName, [referenceDate])
objectName (string): Name of the object (e.g., “Sun”).referenceDate (Date, optional): Overrides the instance date.hourAngle, declination, and distance.const coordinates = astronomy.getHourAngleDeclinationCoordinatesForObject("Sun");
/*
Returns:
{
"hourAngle": 15.45,
"declination": -1.25,
"distance": 0.9958
}
*/
getIlluminatedFractionForObject(objectName, [referenceDate])
objectName (string): Name of the object (e.g., “Moon”).referenceDate (Date, optional): Overrides the instance date.const illuminatedFraction = astronomy.getIlluminatedFractionForObject("Moon");
/*
Returns: 0.253
*/
getEphemerisDateForObject(objectName, referenceDate, ephemerisTypeName)
objectName (string): e.g., “Sun”.referenceDate (Date): The date to search around.ephemerisTypeName (string): e.g., “SUNRISE”, “SUNSET”, “CIVIL_TWILIGHT_START”.Date or null.const sunrise = astronomy.getEphemerisDateForObject("Sun", new Date(), "SUNRISE");
// Returns: 2024-03-20T06:15:22.000Z
getLocalMeanSiderealTime()
const localMeanSiderealTime = astronomy.getLocalMeanSiderealTime();
// Returns: 185.45
getLatitudeLongitudeCoordinates()
latitude and longitude.const coordinates = astronomy.getLatitudeLongitudeCoordinates();
/*
Returns:
{
"latitude": 52.52,
"longitude": 13.405
}
*/
getObserverLocation()
ObserverLocation object or null.const location = astronomy.getObserverLocation();
// Returns: ObserverLocation { longitude: 13.405, latitude: 52.52, ... }
getSkyObjectByName(objectName)
objectName (string): Name of the object (e.g., “Jupiter”).SolarSystemObject data or null.const jupiter = astronomy.getSkyObjectByName("Jupiter");
// Returns: Jupiter { name: "Jupiter", ... }
The library includes data for major solar system bodies and various ephemeris events.
Sun, MoonMercury, Venus, Earth, Mars, Jupiter, Saturn, Uranus, NeptunePlutoUse these names with getEphemerisDateForObject:
RISE, SET, SUNRISE, SUNSET, MOONRISE, MOONSETCIVIL_TWILIGHT_START, CIVIL_TWILIGHT_ENDNAUTICAL_TWILIGHT_START, NAUTICAL_TWILIGHT_ENDASTRONOMICAL_TWILIGHT_START, ASTRONOMICAL_TWILIGHT_ENDGOLDEN_HOUR_START, GOLDEN_HOUR_END<script type="text/javascript" src="astronomy-js.min.js"></script>
// latitude, longitude
let astronomyJS = AstronomyJS.initialize(56.2, 18.1)
astronomyJS.getAltitudeAzimuthCoordinatesForObject("Sun");
npm install astronomy-js
import { AstronomyJS } from "astronomy-js";
// latitude, longitude
let astronomyJS = AstronomyJS.initialize(56.2, 18.1)
astronomyJS.getAltitudeAzimuthCoordinatesForObject("Sun");
This project is licensed under the MIT License — feel free to use, modify, and share it.
Please make sure to retain the original license and attribution when reusing or modifying the code.
See the LICENSE file for full details.
This library provides astronomical calculations for leisure purposes only. Some important basic aspects are not implemented, such as:
![]()
US Naval Observatory, Explanatory Supplement to the Astronomical Almanac, 1992