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
GPS
objectDeclaration
Swift
public init(latitude: Double, longitude: Double)
Parameters
latitude
Latitude of the GPS coordinate
longitude
Longitude of the GPS coordinate
-
Initiazlies a new
GPS
objectDeclaration
Swift
public init(locationCoordinate: CLLocationCoordinate2D)
Parameters
locationCoordinate
A
CLLocationCoordinate2D
to create theGPS
object 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) -> Double
Parameters
gps
Distance to this
GPS
coordinateReturn Value
Distance in units matching
GPS.planetRadius
units. -
Distance to a point using the Haversine formula. More accurate than equirectangular but more time consuming.
Declaration
Swift
public func distanceToHaversine(gps: GPS) -> Double
Parameters
gps
Distance to this
GPS
coordinateReturn Value
Distance in units matching
GPS.planetRadius
units. -
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() -> GPS
Return Value
A
GPS
coordinate referring to the opposite side of the planet. -
Calculate the time of sunrise at the instance
GPS
Declaration
Swift
public func sunriseTime(date: Date, sunZenith: SunZenith) -> Date?
Parameters
date
Requested
Date
for sunrise time. (UTC)sunZenith
Requested
GPS.SunZenith
for sunrise timeReturn Value
Date
of the sunrise time (UTC). Null if no sunrise on this day -
Calculate the time of sunset at the instance
GPS
Declaration
Swift
public func sunsetTime(date: Date, sunZenith: SunZenith) -> Date?
Parameters
date
Requested
Date
for sunset time. (UTC)sunZenith
Requested
GPS.SunZenith
for sunset timeReturn Value
Date
of the sunset time (UTC). Null if no sunset on the day -
Calculate the duration of the day at the instance
GPS
Declaration
Swift
public func dayDuration(date: Date, sunZenith: SunZenith) -> Double
Parameters
date
The requested
Date
for day durationsunZenith
The requested
GPS.SunZenith
for 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
GPS
Declaration
Swift
public func bearingTo(gps: GPS) -> Double
Parameters
gps
GPS
to find the heading to.Return Value
The bearing to the given
GPS
in degrees. (between 0 and 360) -
Halfway along the great circle path between two coordinates
Declaration
Swift
public func midpointTo(gps: GPS) -> GPS
Parameters
f
Origin
GPS
s
Destination
GPS
Return Value
GPS
of 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) -> Double
Parameters
f
First
GPS
s
Second
GPS
Return 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) -> Double
Parameters
f
First
GPS
s
Second
GPS
Return Value
Distance from f to s in units matching
GPS.planetRadius
-
Calculate the bearing between two
GPS
Declaration
Swift
public static func bearingBetweenCoordinates(f: GPS, s: GPS) -> Double
Parameters
f
First
GPS
(heading from)s
Second
GPS
(heading to)Return Value
The bearing to the given
GPS
in 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) -> GPS
Parameters
f
Origin
GPS
s
Destination
GPS
Return Value
GPS
of 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) -> GPS
Parameters
gps
GPS
to operate withReturn Value
GPS
of 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
coordinate
Decimal 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) -> Double
Parameters
degrees
Degrees of coordinate to convert
minutes
Minutes of coordinate to convert
seconds
Seconds 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) -> Double
Parameters
atHeight
Height 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) -> Double
Parameters
atHeight
Height in meters
-
Calculate the time of sunset
Declaration
Swift
public static func sunsetTime(gps: GPS, date: Date, sunZenith: SunZenith) -> Date?
Parameters
gps
GPS
to find the time of sunset atdate
Date
on which to find the sunset time. (UTC)sunZenith
GPS.SunZenith
to 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
gps
GPS
to find the time of sunrise atdate
Date
on which to find the sunrise time. (UTC)sunZenith
GPS.SunZenith
to 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) -> Double
Parameters
gps
GPS
to calculate the day duration ofdate
Date
on which to calculate day duration (UTC)sunZenith
GPS.SunZenith
to 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