Skip to content

cocologics/suncalc-swift

 
 

Repository files navigation

suncalc-swift

This is a swift port for iOS of https://github.com/mourner/suncalc

This code is based on the original Javascript suncalc by Vladimir Agafonkin ("mourner").

// get today's sunlight times for London

let date:NSDate = NSDate()
let sunCalc:SunCalc = SunCalc.getTimes(date, latitude: 51.5, longitude: -0.1)

var formatter:NSDateFormatter = NSDateFormatter()
formatter.dateFormat = "HH:mm"
formatter.timeZone = NSTimeZone(abbreviation: "GMT")
var sunriseString:String = formatter.stringFromDate(sunCalc.sunrise)
println("sunrise is at \(sunriseString)")

let sunPos:SunPosition = SunCalc.getSunPosition(date, latitude: 51.5, longitude: -0.1)

var sunriseAzimuth:Double = sunPos.azimuth * 180 / Constants.PI()
println("sunrise azimuth: \(sunriseAzimuth)")

Packages

No packages published

Languages

  • Swift 97.4%
  • Ruby 2.6%