Astronomy API: Documentation
Get Started with our Astronomy APIs
Get information on astronomical events and the position of celestial objects – with a few lines of code in your language of choice.
Install Official Libraries
To get started, use one of timeanddate.com's official API libraries for your programming language. If your language isn't supported, you can send the requests manually over HTTP. If you would like to request an official library for your language, please contact us.
$ dotnet add package TimeAndDate.Services
Build Query
The API library is now installed. Next, you specify the data you want, the location, and the dates you are querying for. To perform the query, you will need your access key and secret key: Get them from the Access Key page on My Account.
Don't have a key? Sign up for our free trial and receive an access key to try it out.
var coordinates = new Coordinates(59.743m, 10.204m);
var place = new LocationId(coordinates);
var date = new DateTime(2020, 11, 26);
var service = new AstronomyService('accessKey', 'secretKey');
service.Types = AstronomyEventClass.Meridian | AstronomyEventClass.Phase;
Get Result
The astroInfo
variable will now contain the following information when the Moon is at the Meridian as well as it's phase on 2020-11-26: time, altitude, distance, and illumination of the Moon at its highest point in the night sky.
var astroInfo = service.GetAstronomicalInfo(AstronomyObjectType.Moon, place, date);
Where to go next?
See our GitHub repository for more information on the C#/.NET Library.
<repository>
<id>github</id>
<name>Time and Date API Packages</name>
<url>https://maven.pkg.github.com/timeanddate/libtad-jvm</url>
</repository>
<dependency>
<groupId>com.timeanddate</groupId>
<artifactId>services</artifactId>
<version>1.0.0-SNAPSHOT</version>
</dependency>
Build Query
The API library is now installed. Next, you specify the data you want, the location, and the dates you are querying for. To perform the query, you will need your access key and secret key: Get them from the Access Key page on My Account.
Don't have a key? Sign up for our free trial and receive an access key to try it out.
Coordinates coordinates = new Coordinates(59.743m, 10.204m);
LocationId place = new LocationId(coordinates);
TADDateTime date = new TADDateTime(2015, 1, 1);
AstronomyService service = new AstronomyService('accessKey', 'secretKey');
service.Types = EnumSet.of(AstronomyEventClass.MERIDIAN, AstronomyEventClass.MERIDIAN);
Get Result
The astroInfo
variable will now contain the following information when the Moon is at the Meridian as well as it's phase on 2020-11-26: time, altitude, distance, and illumination of the Moon at its highest point in the night sky.
List<AstronomyLocation> astroInfo = service.getAstronomicalInfo(AstronomyObjectType.Moon, place, date);
Where to go next?
See our GitHub repository for more information on the Java/JVM Library.
# Carthage
github "TimeAndDate/TadApi"
# CocoaPods
pod 'libtad-swift', '~> 1.0'
Build Query
The API library is now installed. Next, you specify the data you want, the location, and the dates you are querying for. To perform the query, you will need your access key and secret key: Get them from the Access Key page on My Account.
Don't have a key? Sign up for our free trial and receive an access key to try it out.
let astronomyService = AstronomyService(accessKey: "accessKey", secretKey:"secretKey")
let astronomyRequest = AstronomyRequest()
astronomyRequest.objects = [AstroObjectType.moon]
astronomyRequest.placeId = "+59.743-10.204m"
astronomyRequest.startDate = Date()
astronomyRequest.types = [EventClass.meridian, EventClass.phase]
Get Result
The astroInfo
variable will now contain the following information when the Moon is at the Meridian as well as it's phase on 2020-11-26: time, altitude, distance, and illumination of the Moon at its highest point in the night sky.
astronomyService.getAstronomicalInfo(request:astronomyRequest) { (result, error) in
print(result)
}
Where to go next?
See our GitHub repository for more information on the Swift Library.
Build Query
You will need cURL installed in order to execute the following commands. The following samples also require you to have enabled "Insecure Methods" on your access key.
$ ACCESSKEY="<Your Access Key>"
$ SECRETKEY="<Your Secret Key>"
$ curl -G \
--data-urlencode "version=3" \
--data-urlencode "prettyprint=1" \
--data-urlencode "accesskey=$ACCESSKEY" \
--data-urlencode "secretkey=$SECRETKEY" \
--data-urlencode "placeid=norway/oslo" \
--data-urlencode "object=moon" \
--data-urlencode "types=meridian,phase" \
--data-urlencode "startdt=2020-11-26" \
https://api.xmltime.com/astronomy
Get Result
Execute cURL with the parameters set previously and receive the resulting calculation as a JSON object.
{
"version": 3,
"billing": {
"credits": 1
},
"locations": [{
"id": "187",
"geo": {
"name": "Oslo",
"country": {
"id": "no",
"name": "Norway"
},
"latitude": 59.913,
"longitude": 10.740
},
"matchparam": "187",
"astronomy": {
"objects": [{
"name": "moon",
"days": [{
"date": "2020-11-26",
"events": [{
"type": "meridian",
"hour": 21,
"min": 36,
"sec": 35,
"altitude": 35.6,
"distance": 405882,
"illuminated": 89.0,
"posangle": 333.7
}],
"moonphase": "waxinggibbous"
}]
}]
}
}]
}