A small library to calculate sun rise and sun set time. Provide latitude and longitude, return an UTC Date that's day's sun rise or sun set time. The time zone used during calculation is system time zone. This can avoid a lot of problems.
- Only need latitude and longitude, no need for network
- One line to use this service
Use CocoaPods or Cathage or just pull the DayTimeCalculator.swift file into your project.
To integrate DayTimeCalculator into your Xcode project using CocoaPods, specify it in your Podfile
:
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.0'
use_frameworks!
target 'your_app' do
pod 'DayTimeCalculator', '~> 1.0.0'
end
Then, run the following command:
$ pod install
You should open the {Project}.xcworkspace
instead of the {Project}.xcodeproj
after you installed anything from CocoaPods.
Drag the DayTimeCalculator.swift file into your project
//date is the returned valued
let date = DayTimeCalculator.getSunRiseSetTime(date: Your date(Date() Type), lat: Your latitude, lng: Your longtitude, timeType: .sunRise or .sunSet)
- iOS 8.0+
- Swift 3
The main development of DayTimeCalculator is based on Swift 3.
Follow and contact me through email. If you find an issue, just open a ticket on it. Pull requests are warmly welcome as well.
DayTimeCalculator is released under the MIT license. See LICENSE for details.
Thanks to @junlincao for his algorithm in Java