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.

  • Initiazlizes a new GPS object

    Declaration

    Swift

    public init(latitude: Double, longitude: Double)

    Parameters

    latitude

    Latitude of the GPS coordinate

    longitude

    Longitude of the GPS coordinate

  • Initiazlies a new GPS object

    Declaration

    Swift

    public init(locationCoordinate: CLLocationCoordinate2D)

    Parameters

    locationCoordinate

    A CLLocationCoordinate2D to create the GPS 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 coordinate

    Return 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 coordinate

    Return 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 time

    Return 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 time

    Return 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 duration

    sunZenith

    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

  • 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 with

    Return 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 miles

    Warning

    Doesn’t take refraction into account

    Declaration

    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 kilometers

    Warning

    Doesn’t take refraction into account

    Declaration

    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 at

    date

    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 at

    date

    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 of

    date

    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 more

    Declaration

    Swift

    public enum SunZenith : Double