Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

SunKit is a Swift library which uses math and trigonometry to compute several information about the Sun.

License

NotificationsYou must be signed in to change notification settings

SunKit-Swift/SunKit

Repository files navigation

sunkit

GitHubGitHub starsGitHub issuesRequires Core Location

SunKit is a Swift package that uses math and trigonometry to compute several pieces of information about the Sun.

SunKit was first developed as part of a bigger project:Sunlitt. Even though Sunlitt is not meant to be open-sourced, we decided to wrap the fundamental logic of the app and build a library out of it, free for anyone to use, embrace and extend.

sunkit

Attribution

SunKit is licensed under the Apache License 2.0. For attribution, we request that you include an unmodified vector of SunKit's logo, availablehere, along with our organization name "Sunlitt", both at legible sizes, and that they link back to ourwebsite.

If you are developing an app for Apple platforms, we additionally request that you include SunKit's license and copyright in the "Acknowledgments" section of your app's Settings.bundle file. We have included a Settings.bundle examplehere for you to download and import as is in your Xcode project.

Attribution is essential to make sure that our hard work is properly recognized and we thank you for complying with our requests.

Usage

CoreLocation framework is required for SunKit to work. SunKit only needs a location and the relative time zone. Everything is computed locally, no internet connection is needed.

Creating a Sun

// Creating a CLLocation object with the coordinates you are interested inletnaplesLocation:CLLocation=.init(latitude:40.84014, longitude:14.25226)// Timezone for the location of interest. It's highly recommended to initialize it via identifierlettimeZoneNaples:Timezone=.init(identifier:"Europe/Rome")??.current// Creating the Sun instance which will store all the information you need about sun events and his positionvarmySun:Sun=.init(location: naplesLocation, timeZone: timeZoneNaples)

Retrieve information

// Creating a Date instanceletmyDate:Date=Date() // Your current date// Setting inside mySun object the date of interestmySun.setDate(myDate)      // All the following informations are related to the given location for the date that has just been set// Azimuth of the Sun mySun.azimuth.degrees  // Altitude of the SunmySun.altitude.degrees// Sunrise DatemySun.sunrise// Sunset DatemySun.sunset// Evening Golden Hour Start DatemySun.eveningGoldenHourStart// Evening Golden Hour End DatemySun.eveningGoldenHourEnd// To know all the information you can retrieve go to the **Features** section.

Working with Timezones and Dates

To properly show the Sun Date Events use the following DateFormatter.

 //Creting a DateFormatterletdateFormatter=DateFormatter()  //Properly setting his attributes dateFormatter.locale=.current dateFormatter.timeZone=  timeZoneNaples  // It shall be the same as the one used to initilize mySun dateFormatter.timeStyle=.full dateFormatter.dateStyle=.full   //Printing Sun Date Events with the correct Timezoneprint("Sunrise:\(dateFormatter.string(from: mySun.sunrise))")

Features

  • Sun Azimuth
  • Sun Altitude
  • Civil Dusk Time
  • Civil Dawn Time
  • Sunrise Time
  • Solar Noon Time
  • Solar Midnight Time
  • Morning Golden Hour Time
  • Evening Golden Hour Time
  • Sunset Time
  • Astronomical Dusk
  • Astronomical Dawn
  • Nautical Dusk
  • Nautical Dawn
  • Morning Blue Hour Time
  • Evening Blue Hour Time
  • Sun Azimuth at Sunrise
  • Sun Azimuth at Sunset
  • Sun Azimuth at Solar Noon
  • Total Daylight Duration
  • Total Night Duration
  • March Equinox
  • June Solstice
  • September Equinox
  • December Solstice

References

  • NOAA Global Monitoring Division. General Solar Position Calculations:Link.
  • PV Education:Link.
  • Celestial Calculations: A Gentle Introduction to Computational Astronomy:Link.

MoonKit 🌙

Take a look at SunKit's spiritual brother,MoonKit.

Special thanks

About

SunKit is a Swift library which uses math and trigonometry to compute several information about the Sun.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors3

  •  
  •  
  •  

Languages


[8]ページ先頭

©2009-2025 Movatter.jp