astronomy

JavaScript examples for the browser

You can use the JavaScript version of Astronomy Engine to perform client-side astronomy calculations in a web browser. Calculations are offloaded to the visitor’s computer.

Just grab a copy of astronomy.browser.js or the minimized astronomy.browser.min.js and save it on your server. Inside your HTML code, pull in the script as usual:

<script src="astronomy.browser.js"></script>

Vanilla JS There are no external dependencies! Astronomy Engine is completely self-contained, and it always will be.

(By the way, you can use the file astronomy.js for astronomy calculations in Node.js programs.)

All the functionality is wrapped inside an object called Astronomy.


Functional demo

This is an example of a functioning page that uses Astronomy Engine to calculate some live information about the Moon.

Moon Info calculator by faisalr.


Reference HTML files

Here are more example html files showing how to use Astronomy Engine in a web browser.

Moon Phase Calculator

Determines the Moon’s current phase and predicts when the next few quarter phases will occur.

Moon Radar Pulse Round Trip Calculator

Given a location of an observer on the Earth, calculates the amount of time it takes for a radar pulse to travel from that observer to the Moon and reflect back.

Planet Positions

Calculates equatorial and horizontal coordinates of the Sun, Moon, and planets.

Rise/Set

Shows how to calculate sunrise, sunset, moonrise, and moonset times.

More JavaScript examples

The Node.js examples page has additional JavaScript examples that can be adapted to the browser environment, using the same Astronomy Engine source code.


API Reference

Complete documentation for all the functions and types available in the JavaScript version of Astronomy Engine.