Our Astronomy API provides timings for sunrise, sunset, moonrise, moonset, sun azimuth, moon azimuth, sun altitude, moon altitude, sun distance from the earth and moon distance from the earth from latitude and longitude or an IPv4 or IPv6 address for a given date.
The Astronomy API provides a detailed dataset about twilight timings, different sun and moon parameters for a given date and location.
1{
2 "location": {
3 "ip": "8.8.8.8",
4 "country_code2":"US",
5 "country_name": "United States",
6 "state_prov": "California",
7 "district":"Santa Clara County",
8 "city": "Mountain View",
9 "latitude":37.4229,
10 "longitude": -122.085
11 },
12 "date":"2019-05-09",
13 "sunrise":"06:05",
14 "sunset":"20:05",
15 "solar_noon":"13:05",
16 "day_length":"14:0",
17 "sun_altitude":-33.582817561577535,
18 "sun_distance":150931286.1475694,
19 "sun_azimuth":343.2576441514434,
20 "moonrise":"10:07",
21 "moonset":"00:08",
22 "moon_altitude":0.7748886217638142,
23 "moon_distance":370046.3786130251,
24 "moon_azimuth":298.1799248309394,
25 "moon_parallactic_angle":59.97963452184664
26 }You can pass the latitude and longitude of a location as query parameters to get the astronomical information.
https://api.ipgeolocation.io/astronomy?apiKey=API_KEY&lat=37.258&long=-1221{
2
3"location": {
4 "latitude": 37.258,
5 "longitude": -122
6 },
7"date":"2019-05-09",
8"sunrise":"06:05",
9"sunset":"20:05",
10"solar_noon":"13:05",
11"day_length":"14:0",
12"sun_altitude":-34.72830965022739,
13"sun_distance":150931286.14756945,
14"sun_azimuth":349.12247667674126,
15"moonrise":"10:08",
16"moonset":"",
17"moon_altitude":-3.204265882589777,
18"moon_distance":369999.04749968933,
19"moon_azimuth":301.26481563881885,
20"moon_parallactic_angle":.03255796143746
21}You can pass any IPv4 or IPv6 address as a query parameter to get the astronomical information.
https://api.ipgeolocation.io/astronomy?apiKey=API_KEY&ip=8.8.8.81{
2
3"location": {
4 "ip": "8.8.8.8",
5 "country_code2": "US",
6 "country_name": "United States",
7 "state_prov": "California",
8 "district": "Santa Clara County",
9 "city": "Mountain View",
10 "latitude": 37.4229,
11 "longitude": -122.085
12},
13"date":"2019-05-09",
14"sunrise":"06:05",
15"sunset":"20:05",
16"solar_noon":"13:04",
17"day_length":14:0",
18"sun_altitude":-34.96481239930455,
19"sun_distance":150931286.14756942,
20"sun_azimuth":"352.86344723078366,
21"moonrise":"10:08",
22"moonset":"",
23"moon_altitude":-5.200240231300586,
24"moon_distance":369968.53483416745,
25"moon_azimuth":303.25074811628497,
26"moon_parallactic_angle":61.25712073304896,
27}There's a sunrise and sunset every day and they're absolutely free. Take advantage of them and plan your photography sessions ahead of time for the perfect capture with our sunrise-sunset API.
Planning a game of golf? Make sure you plan your tee for the right light. Because you know what they say, "The most important shot is the first one."
Plan the perfect sunset romantic dinner, hiking trip or star-gazing party by taking advantage of the best star API you can find.
"Twilight is the time of the day when the sky looks like it has been painted by a graffiti artist". Use our astronomy API to plan the perfect time to view this breath-taking phenomenon and explore one of the most over-whelming covers of the heavens.
Trying to figure out the optimal angle for your solar panels? Use our API to get the exact solar azimuth and calculate the best solar panel angle by zip code.
The Astronomy API provides the location-based rise and set times for the Sun and Moon along with the current position, distance from earth, and azimuth of the Sun and the Moon for a specific date at the queried time.
The Astronomy calculations are much more complex than producing an accurate result from obscure formulas throwing in a few numbers. There is always a tradeoff between the accuracy and computing time. Our Astronomy API focuses more on producing an acceptable results and has an accuracy of around one minute that is good enough for applications like sunrise/sunset timers but is not sufficient for astronomical purposes.
There are three ways to consume the Astronomy API:
The three variations of Astronomy API take the different input sources to produce astronomical information along with location details. Here is how to consume each variation:
You can pass the address of a location as query parameters to get the astronomical information. Here is a curl example:
1
2 "location": {
3 "country": "United States of America",
4 "state": "New York",
5 "city": "",
6 "latitude": 41.3558443,
7 "longitude": -74.00776718841271
8 },
9 "date": "2020-12-21",
10 "current_time": "06:54:35.901",
11 "sunrise": "07:18",
12 "sunset": "16:30",
13 "sun_status": "-",
14 "solar_noon": "11:54",
15 "day_length": "09:12",
16 "sun_altitude": -4.811160884765326,
17 "sun_distance": 1.4717185206455985E8,
18 "sun_azimuth": 117.23599031322385,
19 "moonrise": "12:12",
20 "moonset": "23:58",
21 "moon_status": "-",
22 "moon_altitude": -52.075439497726244,
23 "moon_distance": 398627.6792531222,
24 "moon_azimuth": 29.97617258900459,
25 "moon_parallactic_angle": -26.12246297084847
26}Location details like country name, state/province name, and city are provided in the response for the provided location that can be used for multiple purposes.
You can pass the latitude and longitude of a location as query parameters to get the astronomical information. Here is a curl example:
1
2{
3 "location": {
4 "latitude": -27.4748,
5 "longitude": 153.017
6 },
7 "date": "2020-12-21",
8 "current_time": "21:55:42.198",
9 "sunrise": "04:49",
10 "sunset": "18:42",
11 "sun_status": "-",
12 "solar_noon": "11:46",
13 "day_length": "13:53",
14 "sun_altitude": -32.52181803389665,
15 "sun_distance": 1.4717185206455985E8,
16 "sun_azimuth": 210.3191424893586,
17 "moonrise": "10:56",
18 "moonset": "23:51",
19 "moon_status": "-",
20 "moon_altitude": 25.112485813391366,
21 "moon_distance": 398630.7670989189,
22 "moon_azimuth": 275.28650130894704,
23 "moon_parallactic_angle": 122.50665265321304
24}
25 You can pass any IPv4 or IPv6 address as a query parameter to get the astronomical information. Here is a curl example:
1
2 {
3 "location": {
4 "country": "United States of America",
5 "state": "New York",
6 "city": "",
7 "latitude": 41.3558443,
8 "longitude": -74.00776718841271
9 },
10 "date": "2020-12-21",
11 "current_time": "06:54:35.901",
12 "sunrise": "07:18",
13 "sunset": "16:30",
14 "sun_status": "-",
15 "solar_noon": "11:54",
16 "day_length": "09:12",
17 "sun_altitude": -4.811160884765326,
18 "sun_distance": 1.4717185206455985E8,
19 "sun_azimuth": 117.23599031322385,
20 "moonrise": "12:12",
21 "moonset": "23:58",
22 "moon_status": "-",
23 "moon_altitude": -52.075439497726244,
24 "moon_distance": 398627.6792531222,
25 "moon_azimuth": 29.97617258900459,
26 "moon_parallactic_angle": -26.12246297084847
27
28} Note: When you get the astronomical information through an IP address, API will also return the extra fields about place information along with the astronomical information.
You can call the astronomy API without passing any coordinates or IP address as well. It will use the calling machine's IP address to return the regional astronomical information. Here is a curl example:
Note:In above example, we used API Key everywhere. Astronomy API can be called from client side JavaScript with Request Origin authentication as well on paid plans.
The astronomy information lookup using an IP address can include geolocation information the following languages:s
By default, the API responds in English. But you can change the response language by passing the language code as a query parameter lang. Here is an example:
Only the paid plan subscriptions can get the response in languages other than English. All the other subscriptions will only get the response in English.
Along with the above two variations, there is a third variation that you can get the astronomical information for a specific date. You can pass date query parameter with the date value. Here are the curl example calls:
Along with the above two variations, there is a third variation that you can get the astronomical information for a specific date. You can pass date query parameter with the date value. Here are the curl example calls:
Note:Date must be in 'YYYY-MM-DD' format. No other format will be accepted and by default, current date will be used. All the astronomical information is calculated at the current time of day at the provided location.
sun_status is equal to "-" if the sunrise and sunset values are not equal to "-:-". sun_status can be equal to "Always above the twilight angle" or "Always below the twilight angle" if the sun is always up or always set within the current 24 hours of the day.
moon_status is equal to "-" if the moonrise and moonset values are not equal to "-:-". moon_status can be equal to "Always above the horizon" or "Always below the horizon" if the moon is always up or always set within the current 24 hours of the day.