Astronomy API Client Side Plugin
Overview
Get sunrise, sunset, moonrise, moonset, moon phases with precise twilight period times in combination with location information. One can get the astronomy information from any IP address, geo-coordinates, or street address right in your web application. It is recommended to use the request origin feature (available only in paid plans) to ensure your API key is not exposed publicly. You can add your request origin (your website domain) by logging into your account at IPGeolocation.io.
Requirements
- Internet Connection
- API Key from IPGeolocation.io
How to Get Your API Key
- Sign up here: https://app.ipgeolocation.io/signup
- (optional) Verify your email, if you signed up using email.
- Log in to your account: https://app.ipgeolocation.io/login
- After logging in, navigate to your Dashboard to find your API key: https://app.ipgeolocation.io/dashboard
Installation
To access this service, add the following Javascript call (usually within head block of your pages).
This service will only work when embedded in web pages - no server-side calls will work.
Plugin Configurations
To instantiate the AstronomyAPI, you can use the following configuration options:
-
apiKey (optional: string): API key used for request authentication. This field is mandatory unless you have added your request origin in the dashboard, in which case it becomes optional. -
ipAddress (optional: string): Specify an IP address for which you want the astronomical information. If not provided, the client’s IP address is used by default. -
location (optional: string): Specify the location for which you want the astronomical information. -
Coordinates (optional: string): Specify the location coordinates for which you want the astronomical information. -
date (optional: string): Specify the date for which you want the astronomical information. You can pass this along with other parameters (ipAddress, location, coordinates) -
lang (optional: boolean): Language of the response. Default is en. Supported languages include: ru, de, ja, fr, cn, es, cs, it, fa, ko. -
saveToSessionStorage (optional: boolean): Saves geolocation data to session storage for temporary use.
For detailed documentation for the Astronomy API, please visit https://ipgeolocation.io/astronomy-api.html#documentation-overview.
Code Examples
1.Get Astronomical Information for a specific location
Sample Response:
If there is some error while fetching the response from the API, following response will be returned, so handle it accordingly:
2.Get Astronomical Information for Location Coordinates
Sample Response:
3.Get Astronomical Information for an IP Address
Sample Response:
4.Get Astronomical Information for a Specific Date
Sample Response:
Error Handling
Inspect the status field in the response to detect any errors. A missing status field typically indicates a successful request, while its presence signals an issue. For example, if you are trying to fetch the data for a location that does not exist, you will get the following error response:
Sample Response: