GPS
public class GPS : CustomStringConvertible
GPS provides an library for many calculations involving GPS and earth.
A GPS instance contains a latitude and longitude and is used for performing operations in the GPS library. GPS instances have a few instance methods. All instance methods use public static methods for the calculations.
-
Declaration
Swift
public var description: String { get }
-
Undocumented
Declaration
Swift
public var latitude: Double -
Undocumented
Declaration
Swift
public var longitude: Double
-
Initiazlizes a new
GPSobjectDeclaration
Swift
public init(latitude: Double, longitude: Double)Parameters
latitudeLatitude of the GPS coordinate
longitudeLongitude of the GPS coordinate
-
Initiazlies a new
GPSobjectDeclaration
Swift
public init(locationCoordinate: CLLocationCoordinate2D)Parameters
locationCoordinateA
CLLocationCoordinate2Dto create theGPSobject from.
-
Distance to a point using the Equitectangular formula. Units will match planet radius units. Less accurate than Haversine but less time consuming.
Declaration
Swift
public func distanceToEquirectangular(gps: GPS) -> DoubleParameters
gpsDistance to this
GPScoordinateReturn Value
Distance in units matching
GPS.planetRadiusunits. -
Distance to a point using the Haversine formula. More accurate than equirectangular but more time consuming.
Declaration
Swift
public func distanceToHaversine(gps: GPS) -> DoubleParameters
gpsDistance to this
GPScoordinateReturn Value
Distance in units matching
GPS.planetRadiusunits. -
Returns the GPS coordinates on the other side of the world from the instance
GPS. (If you were to dig a hole perfectly straight this is where you would end up)Declaration
Swift
public func oppositeCoordinate() -> GPSReturn Value
A
GPScoordinate referring to the opposite side of the planet. -
Calculate the time of sunrise at the instance
GPSDeclaration
Swift
public func sunriseTime(date: Date, sunZenith: SunZenith) -> Date?Parameters
dateRequested
Datefor sunrise time. (UTC)sunZenithRequested
GPS.SunZenithfor sunrise timeReturn Value
Dateof the sunrise time (UTC). Null if no sunrise on this day -
Calculate the time of sunset at the instance
GPSDeclaration
Swift
public func sunsetTime(date: Date, sunZenith: SunZenith) -> Date?Parameters
dateRequested
Datefor sunset time. (UTC)sunZenithRequested
GPS.SunZenithfor sunset timeReturn Value
Dateof the sunset time (UTC). Null if no sunset on the day -
Calculate the duration of the day at the instance
GPSDeclaration
Swift
public func dayDuration(date: Date, sunZenith: SunZenith) -> DoubleParameters
dateThe requested
Datefor day durationsunZenithThe requested
GPS.SunZenithfor calculating sunrise and sunset and the difference.Return Value
Day duration in seconds. 0 if no sunrise or no sunset on this day.
-
Calculate the bearing to another
GPSDeclaration
Swift
public func bearingTo(gps: GPS) -> DoubleParameters
gpsGPSto find the heading to.Return Value
The bearing to the given
GPSin degrees. (between 0 and 360) -
Halfway along the great circle path between two coordinates
Declaration
Swift
public func midpointTo(gps: GPS) -> GPSParameters
fOrigin
GPSsDestination
GPSReturn Value
GPSof midpoint
-
Undocumented
Declaration
Swift
public static let MAX_LATITUDE: Double -
Undocumented
Declaration
Swift
public static let MIN_LATITUDE: Double -
Undocumented
Declaration
Swift
public static let MIN_LONGITUDE: Double -
Undocumented
Declaration
Swift
public static let MAX_LONGITUDE: Double -
Radius of Earth (Miles)
Declaration
Swift
public static let EARTH_RADIUS: Double -
Radius of Earth (Kilometers)
Declaration
Swift
public static let EARTH_RADIUS_METRIC: Double -
Radius of Moon (Miles)
Declaration
Swift
public static let MOON_RADIUS: Double -
Radius of Moon (Kilometers)
Declaration
Swift
public static let MOON_RADIUS_METRIC: Double -
Radius of Mars (Miles)
Declaration
Swift
public static let MARS_RADIUS: Double -
Radius of Mars (Kilometers)
Declaration
Swift
public static let MARS_RADIUS_METRIC: Double -
Planet Radius used for calculations. Defaults to radius of Earth in Miles.
Declaration
Swift
public static var planetRadius: Double
-
Distance to a point using the Haversine formula. More accurate than equirectangular but more time consuming.
Declaration
Swift
public static func distanceBetweenHaversine(f: GPS, s: GPS) -> DoubleParameters
fFirst
GPSsSecond
GPSReturn Value
Distance from f to s in units matching
GPS.planetRadius -
Distance to a point using the Equirectangular formula. More less than Haversine but less time consuming. Can be used accuratly for short distances on earth. When calculating distances on other planets, use equirectangular always.
Declaration
Swift
public static func distanceBetweenEquirectangular(f: GPS, s: GPS) -> DoubleParameters
fFirst
GPSsSecond
GPSReturn Value
Distance from f to s in units matching
GPS.planetRadius -
Calculate the bearing between two
GPSDeclaration
Swift
public static func bearingBetweenCoordinates(f: GPS, s: GPS) -> DoubleParameters
fFirst
GPS(heading from)sSecond
GPS(heading to)Return Value
The bearing to the given
GPSin degrees. (between 0 and 360. 0 is North) -
Halfway along the great circle path between two coordinates
Declaration
Swift
public static func midpointCoordinate(f: GPS, s: GPS) -> GPSParameters
fOrigin
GPSsDestination
GPSReturn Value
GPSof midpoint -
GPS coordinates on the other side of the world. (If you were to dig a hole perfectly straight this is where you would end up)
Declaration
Swift
public static func oppositeCoordinate(gps: GPS) -> GPSParameters
gpsGPSto operate withReturn Value
GPSof opposite coordinate -
Convert decimal format coordinates to degrees, minutes, seconds
Declaration
Swift
public static func toDegreesMinuteSecond(coordinate: Double) -> (degrees: Double, minutes: Double, seconds: Double)Parameters
coordinateDecimal version of coordinate
Return Value
Tuple containing degrees, minutes, and seconds
-
Convert degrees minutes and seconds to decimal format
Declaration
Swift
public static func toDecimal(degrees: Double, minutes: Double, seconds: Double) -> DoubleParameters
degreesDegrees of coordinate to convert
minutesMinutes of coordinate to convert
secondsSeconds of coordinate to convert
Return Value
Double representing decimal value of coordinate
-
Calculates the distance to the horizon.
Precondition
Planet radius must be in milesWarning
Doesn’t take refraction into accountDeclaration
Swift
public static func distanceToHorizon(atHeight: Double) -> DoubleParameters
atHeightHeight in feet
Return Value
Distance to the horizon (miles)
-
Calculates the distance to the horizon.
Precondition
Planet radius must be in kilometersWarning
Doesn’t take refraction into accountDeclaration
Swift
public static func distanceToHorizonMetric(atHeight: Double) -> DoubleParameters
atHeightHeight in meters
-
Calculate the time of sunset
Declaration
Swift
public static func sunsetTime(gps: GPS, date: Date, sunZenith: SunZenith) -> Date?Parameters
gpsGPSto find the time of sunset atdateDateon which to find the sunset time. (UTC)sunZenithGPS.SunZenithto calculate sunset time with. (Zenith specifies the angle of the sun. Official is when it just dips below the horizon)Return Value
Date of sunset (UTC). Null when no sunset on the given date.
-
Calculate the time of sunrise
Declaration
Swift
public static func sunriseTime(gps: GPS, date: Date, sunZenith: SunZenith) -> Date?Parameters
gpsGPSto find the time of sunrise atdateDateon which to find the sunrise time. (UTC)sunZenithGPS.SunZenithto calculate sunrise time with. (Zenith specifies the angle of the sun. Official is when it just breaks the horizon)Return Value
Date of sunset (UTC). Null when no sunrise on the given date.
-
Returns the duration of the day in seconds at a given GPS coordinate on a given day with a given sun zenith Calculate the duration of the day
Declaration
Swift
public static func dayDuration(gps: GPS, date: Date, sunZenith: SunZenith) -> DoubleParameters
gpsGPSto calculate the day duration ofdateDateon which to calculate day duration (UTC)sunZenithGPS.SunZenithto calculate day duration with.Return Value
Duration of the day in seconds. 0 if there is no sunset or there is no sunrise.
-
Sun Zenith is used to describe the angle of the sun relative to the surface of earth for calculations involving sun phases.
See moreDeclaration
Swift
public enum SunZenith : Double
View on GitHub
Install in Dash
GPS Class Reference