API Freaks logoAPI Freaks logo
CTRL+K

    Documentation

  • Pricing

  • Resources

  • Tools

  • Contact us

CTRL+K
Sign InGet Started For Free
  • Overview
  • Documentation
  • How to Guides
  • Pricing
  • APIFreaks
  • Organization and Teams
  • Credits Usage API
  • IP Geolocation Lookup API
  • Bulk IP Geolocation Lookup
  • Domain WHOIS Lookup
  • IP WHOIS Lookup
  • ASN Lookup
  • Domain WHOIS Historical Lookup
  • Domain WHOIS Reverse Lookup
  • Bulk Domain WHOIS Lookup
  • DNS Lookup
  • Historical DNS Lookup
  • Reverse DNS Lookup
  • Bulk DNS Lookup
  • SSL Certificate Lookup
  • Domain Availability API
  • Bulk Domain Availability API
  • Screenshot API
  • Bulk Screenshot API
  • Currencies Exchange Rates API
  • Currency Converter API
  • Currency Time Series API
  • Currency Fluctuation API
  • Geolocalized Currency Converter
  • Live Commodity Prices
  • Commodity Historical Prices
  • Commodity Fluctuation API
  • Commodity Time Series API
  • Timezone Lookup
  • Timezone Converter
  • Zipcode Lookup API
  • User Agent Parser
  • Bulk User Agent Parser
  • Astronomy API

Astronomy API - Location Based Astronomy Data

Retrieve sunrise and sunset times, the current position of the moon, and other related information by specifying a location address, coordinates, or IP address. If no parameters are provided, the API will use the client IP address. You can also specify a date to get astronomical data for any specific day.

There are three ways to consume astronomy API:

  1. Using address (preferably city address)
  2. Using location coordinates (latitude and longitude)
  3. Using an IP address

When requesting information using an IP address with the astronomy API, you can also specify an additional "lang" parameter to receive geolocation information in multiple languages.

10K Free Credits, No Credit Card Required

Features

Location Based Data

Get precise sunrise and sunset times, current position and distance of the sun and moon, azimuth of sun and moon and other astronomy data for any location.

Multiple Input Methods

Use address, location coordinates, or IP address to fetch astronomical information, making it versatile and user-friendly.

Real-Time Calculations

Get accurate astronomical data with an accuracy of around one minute, suitable for applications like sunrise/sunset timers.

Timeless Astronomical Insights

Retrieve detailed astronomical data for any date in the past and get accurate predictions for future astronomical events.

Custom Timezone Support

Specify any timezone to receive astronomical data calculated according to your preferred time zone, making it easy to integrate globally.

Elevation-Aware Calculations

Incorporate elevation into your queries to enhance the accuracy of sunrise, sunset, and twilight calculations for high-altitude locations.

Documentation

API Endpoint

GET

https://api.apifreaks.com/v1.0/geolocation/astronomy

Test
LANGUAGE
Python
PHP
Java
Node
Ruby
JavaScript
C#
$ pip install requests

API Request

ParameterRequiredTypeDefaultDescription
locationNoString-Extract astronomy information using location (preferably city)
latNoFloat-Latitude to extract astronomy information using location coordinates
longNoFloat-Longitude to extract astronomy information using location coordinates
ipNoStringrequest ipIPv4 or IPv6 address to extract astronomy information using IP address
langNoStringenResponse language of "location" field in case of lookup through IP address only. Possible values are: (1) en (English) (2) de (German) (3) ru (Russian) (4) ja (Japanese) (5) fr (French) (6) cn (Chinese Simplifed) (7) es (Spanish) (8) cs (Czech) (9) it (Italian)
dateNoString-Specific date (format YYYY-MM-DD) for which astronomy data is required
elevationNoFloat0Elevation above sea level at the location, in meters. The value should be between 0 meter and a maximum value of 10,000 meters. Negative value is set to 0.
time_zoneNoString-Time zone to receive all time-based data in your preferred local time.

API Response

For a comprehensive view of the API response structure and detailed field descriptions, explore the interactive Response Table by clicking here.

HTTP Error Codes

HTTP StatusReasons
400
(1) When provided location Address could not be geocoded (2) When provided ip is not found in the database (3) When date format is not correct (4) When latitude and longitude are not valid

How-To-Guides

Astronomical Information for an Address

Pass the address using location query parameter to get the astronomical information.

# Get astronomical information for address 'New York, US'
$ curl -X 'GET' 'https://api.apifreaks.com/v1.0/geolocation/astronomy?apiKey=API-KEY&location=New%20York,%20US'
# Response { "location": { "location_string": "new york,New York, US", "country_name": "United States", "state_prov": "New York", "city": "New York", "locality": "Clinton", "latitude": "40.76473", "longitude": "-74.00084", "elevation": "9" }, "astronomy": { "date": "2025-08-06", "current_time": "04:03:37.659", "mid_night": "01:02", "night_end": "04:09", "morning": { "astronomical_twilight_begin": "04:09", "astronomical_twilight_end": "04:50", "nautical_twilight_begin": "04:50", "nautical_twilight_end": "05:27", "civil_twilight_begin": "05:27", "civil_twilight_end": "05:57", "blue_hour_begin": "05:15", "blue_hour_end": "05:39", "golden_hour_begin": "05:39", "golden_hour_end": "06:36" }, "sunrise": "05:57", "sunset": "20:06", "evening": { "golden_hour_begin": "19:27", "golden_hour_end": "20:23", "blue_hour_begin": "20:23", "blue_hour_end": "20:47", "civil_twilight_begin": "20:06", "civil_twilight_end": "20:35", "nautical_twilight_begin": "20:35", "nautical_twilight_end": "21:12", "astronomical_twilight_begin": "21:12", "astronomical_twilight_end": "21:52" }, "night_begin": "21:52", "sun_status": "-", "solar_noon": "13:01", "day_length": "14:08", "sun_altitude": -18.85001014751317, "sun_distance": 151765334.54452804, "sun_azimuth": 46.1663368599589, "moon_phase": "WAXING_GIBBOUS", "moonrise": "18:48", "moonset": "02:38", "moon_status": "-", "moon_altitude": -13.181912288976507, "moon_distance": 393253.604156052, "moon_azimuth": 244.10081380457763, "moon_parallactic_angle": 50.56690518856842, "moon_illumination_percentage": "90.30", "moon_angle": 143.70019251110975 } }

Astronomical Information for Location Coordinates

Pass the latitude and longitude of a location as query parameters lat and long to get the astronomical information.

# Get astronomical information for address 'New York, US'
$ curl -X 'GET' 'https://api.apifreaks.com/v1.0/geolocation/astronomy?apiKey=API-KEY&lat=40.712&long=-74.006'
# Response { "location": { "latitude": "40.71200", "longitude": "-74.00600", "country_name": "United States", "state_prov": "New York", "city": "New York", "locality": "Financial District", "elevation": "6" }, "astronomy": { "date": "2025-08-06", "current_time": "04:04:23.522", "mid_night": "01:02", "night_end": "04:10", "morning": { "astronomical_twilight_begin": "04:10", "astronomical_twilight_end": "04:50", "nautical_twilight_begin": "04:50", "nautical_twilight_end": "05:27", "civil_twilight_begin": "05:27", "civil_twilight_end": "05:57", "blue_hour_begin": "05:15", "blue_hour_end": "05:39", "golden_hour_begin": "05:39", "golden_hour_end": "06:36" }, "sunrise": "05:57", "sunset": "20:05", "evening": { "golden_hour_begin": "19:27", "golden_hour_end": "20:23", "blue_hour_begin": "20:23", "blue_hour_end": "20:47", "civil_twilight_begin": "20:05", "civil_twilight_end": "20:35", "nautical_twilight_begin": "20:35", "nautical_twilight_end": "21:12", "astronomical_twilight_begin": "21:12", "astronomical_twilight_end": "21:52" }, "night_begin": "21:52", "sun_status": "-", "solar_noon": "13:01", "day_length": "14:08", "sun_altitude": -18.784819024484214, "sun_distance": 151765334.54452807, "sun_azimuth": 46.33395999604511, "moon_phase": "WAXING_GIBBOUS", "moonrise": "18:48", "moonset": "02:38", "moon_status": "-", "moon_altitude": -13.280527337717585, "moon_distance": 393251.31303562754, "moon_azimuth": 244.19299873353634, "moon_parallactic_angle": 50.67627072849638, "moon_illumination_percentage": "90.30", "moon_angle": 143.70638879873655 } }

Astronomical Information for an IPv4 or IPv6 Address

Pass any IPv4 or IPv6 address as the ip query parameter to get the astronomical information.

# Get astronomical information for an IP address '1.1.1.1'
$ curl 'https://api.apifreaks.com/v1.0/geolocation/astronomy?apiKey=API-KEY&ip=1.1.1.1'
# Response { "location": { "location_string": "new york", "country_name": "United States", "state_prov": "New York", "city": "New York", "locality": "", "latitude": "40.71273", "longitude": "-74.00602", "elevation": "6" }, "astronomy": { "date": "2025-08-06", "current_time": "04:04:59.463", "mid_night": "01:02", "night_end": "04:10", "morning": { "astronomical_twilight_begin": "04:10", "astronomical_twilight_end": "04:50", "nautical_twilight_begin": "04:50", "nautical_twilight_end": "05:27", "civil_twilight_begin": "05:27", "civil_twilight_end": "05:57", "blue_hour_begin": "05:15", "blue_hour_end": "05:39", "golden_hour_begin": "05:39", "golden_hour_end": "06:36" }, "sunrise": "05:57", "sunset": "20:05", "evening": { "golden_hour_begin": "19:27", "golden_hour_end": "20:23", "blue_hour_begin": "20:23", "blue_hour_end": "20:47", "civil_twilight_begin": "20:05", "civil_twilight_end": "20:35", "nautical_twilight_begin": "20:35", "nautical_twilight_end": "21:12", "astronomical_twilight_begin": "21:12", "astronomical_twilight_end": "21:52" }, "night_begin": "21:52", "sun_status": "-", "solar_noon": "13:01", "day_length": "14:08", "sun_altitude": -18.702215772647552, "sun_distance": 151765334.54452798, "sun_azimuth": 46.45809177113347, "moon_phase": "WAXING_GIBBOUS", "moonrise": "18:48", "moonset": "02:38", "moon_status": "-", "moon_altitude": -13.37900351939292, "moon_distance": 393249.5175100612, "moon_azimuth": 244.27635182539376, "moon_parallactic_angle": 50.72434980333764, "moon_illumination_percentage": "90.30", "moon_angle": 143.71124463618955 } }

When getting astronomical information using IP address, the response will also contain geolocation information in the location field. To get the geolocation information in a specific language, provide the language code using the lang parameter. Default geolocation response is in English.

# Get astronomical information for IP = 1.1.1.1 with geolocation in Spanish
$ curl 'https://api.apifreaks.com/v1.0/geolocation/astronomy?apiKey=API-KEY&ip=1.1.1.1&lang=es'
The languages supported are:
  1. en (English)
  2. de (German)
  3. ru (Russian)
  4. ja (Japanese)
  5. fr (French)
  6. cn (Chinese Simplifed)
  7. es (Spanish)
  8. cs (Czech)
  9. it (Italian)

Astronomical Information for a Specific Date

Pass the date query parameter in 'YYYY-MM-DD' format to get the astronomical information for a specific date. If no date is provided the current date will be used. All the astronomy data is calculated at the current time of day at the provided location.

# Get astronomical information for date 2023-01-01 for a particular coordinate
$ curl 'https://api.apifreaks.com/v1.0/geolocation/astronomy?apiKey=API-KEY&lat=-29.1763&long=131.121&date=2023-01-01'
# Get astronomical information for date 2023-01-01 for an ip address
$ curl 'https://api.apifreaks.com/v1.0/geolocation/astronomy?apiKey=API-KEY&ip=1.1.1.1&date=2023-01-01'

Astronomical Information for Calling Machine IP

Call the API without passing any location, coordinates, or IP address. It will use the calling machine's IP address to return the regional astronomical information.

$ curl 'https://api.apifreaks.com/v1.0/geolocation/astronomy?apiKey=API-KEY'

Pricing

To use the Astronomy API, API credits are required. Charges apply only for successful queries, defined by a 2xx status code. If a request results in a 4xx or 5xx status code, no credits will be deducted, and any credits already charged will be refunded.

For each successful request, 1 credit will be charged for astronomical data. Utilize the Credits Usage API to efficiently monitor your recent consumption of both one-off and subscription credits. This API provides a streamlined way to track and manage your credit usage, ensuring you stay informed about your remaining balance and can optimize your resource allocation effectively.

Price Estimation Calculator

Ready to get started?

Sign Up for Free

APIFreaks

API Catalog

  • Geolocation APIs
  • WHOIS APIs
  • DNS APIs
  • SSL APIs
  • Domain Availability APIs
  • Screenshot APIs
  • Currency APIs
  • Commodity APIs
  • Timezone APIs
  • Zipcode APIs
  • User Agent APIs
  • Other APIs

Tools Catalog

  • Formatters & Beautifiers
  • Converters & Optimizers
  • Viewers & Validators

Docs

  • Documentation
  • Swagger Docs

Pricing & Accounts

  • Pricing
  • Sign up
  • Sign In

Company

  • About Us
  • Resources
  • Terms
  • Privacy

Copyright © 2024

Made in Pakistan