GeoCoordinate

public protocol GeoCoordinate

Protocol for describing geo coordinates

Types that conform to the GeoCoordinate protocol can be used with GPXKits utility functions, for example distance or bounds calculations. Adding GeoCoordinate conformance to your custom types means that your types must provide readable getters for latitude and longitude degree values.

  • Latitude value in degrees

    Declaration

    Swift

    var latitude: Double { get }
  • Longitude value in degrees

    Declaration

    Swift

    var longitude: Double { get }
  • Compute the distance between two points on an ellipsoid.

    Throws

    Throws:

    The ellipsoid parameters default to the WGS-84 parameters. Details. Sample implementation in Swift.

    Declaration

    Swift

    public func distanceVincenty(to: GeoCoordinate,
                                 tol: Double = 1e-12,
                                 maxIter: UInt = 200,
                                 ellipsoid: (a: Double, f: Double) = wgs84) throws -> Double

    Parameters

    x

    first point with latitude and longitude in radiant.

    y

    second point with latitude and longitude in radiant.

    tol

    tolerance for the computed distance (in meters)

    maxIter

    maximal number of iterations

    a

    first ellipsoid parameter in meters (defaults to WGS-84 parameter)

    f

    second ellipsoid parameter in meters (defaults to WGS-84 parameter)

    Return Value

    distance between x and y in meters.

  • Calculates the radius in meters around a coordinate for a latitude delta.

    One degree of latitude is always approximately 111 kilometers (69 miles). So the radius can derived from the delta (the coordinates latitude minus latitudeDelta/2).

    Declaration

    Swift

    public func radiusInMeters(latitudeDelta: Double) -> Double

    Parameters

    latitudeDelta

    The latitude delta.

    Return Value

    The radius in meters.

  • bounds(distanceInMeters:) Extension method

    Calculates the GeoBounds for a GeoCoordinate around a given radius in meters.

    Details on Jan Philip Matuscheks website

    Declaration

    Swift

    public func bounds(distanceInMeters: Double) -> GeoBounds?

    Parameters

    distanceInMeters

    Distance in meters around the coordinate.

    Return Value

    A GeoBounds value or nil if no bounds could be calculated (if distanceInMeters is below zero).

  • validLatitudeRange Extension method

    A range of valid latitude values (from -90 to 90 degrees)

    Declaration

    Swift

    static var validLatitudeRange: ClosedRange<Double> { get }
  • validLongitudeRange Extension method

    A range of valid longitude values (from -180 to 180 degrees)

    Declaration

    Swift

    static var validLongitudeRange: ClosedRange<Double> { get }
  • distance(to:) Extension method

    Calculates the distance in meters to another GeoCoordinate.

    Declaration

    Swift

    func distance(to: GeoCoordinate) -> Double

    Parameters

    to

    Destination coordinate (given latitude & longitude degrees) to which the distance should be calculated.

    Return Value

    Distance in meters.

  • mercatorProjectionToMeters() Extension method

    Performs a mercator projection of a geo coordinate to values in meters along x/y

    This produces a fast approximation to the truer, but heavier elliptical projection, where the Earth would be projected on a more accurate ellipsoid (flattened on poles). As a consequence, direct measurements of distances in this projection will be approximative, except on the Equator, and the aspect ratios on the rendered map for true squares measured on the surface on Earth will slightly change with latitude and angles not so precisely preserved by this spherical projection. More details on Wikipedia

    Declaration

    Swift

    func mercatorProjectionToMeters() -> (x: Double, y: Double)

    Return Value

    A pair of x/y-values in meters.

  • Performs a mercator projection of a geo coordinate to values in degrees

    This produces a fast approximation to the truer, but heavier elliptical projection, where the Earth would be projected on a more accurate ellipsoid (flattened on poles). As a consequence, direct measurements of distances in this projection will be approximative, except on the Equator, and the aspect ratios on the rendered map for true squares measured on the surface on Earth will slightly change with latitude and angles not so precisely preserved by this spherical projection. More details on Wikipedia

    Declaration

    Swift

    func mercatorProjectionToDegrees() -> (x: Double, y: Double)

    Return Value

    A pair of x/y-values in latitude/longitude degrees.

  • offset(north:east:) Extension method

    Helper method for offsetting a GeoCoordinate. Useful in tests or for tweaking a known location

    let position = Coordinate(latitude: 51.323331, longitude: 12.368279)
    position.offset(east: 60),
    position.offset(east: -100),
    position.offset(north: 120),
    position.offset(north: -160),
    

    See here for more details.

    Declaration

    Swift

    func offset(north: Double = 0, east: Double = 0) -> Coordinate

    Parameters

    north

    The offset in meters in vertical direction as seen on a map. Use negative values to go upwards on a globe, positive values for moving downwards.

    east

    The offset in meters in horizontal direction as seen on a map. Use negative values to go to the west on a globe, positive values for moving in the eastern direction.

    Return Value

    A new Coordinate value, offset by north and east values in meters.

  • bearing(target:) Extension method

    Calculates the bearing of the coordinate to a second

    Declaration

    Swift

    func bearing(target: Coordinate) -> Double

    Parameters

    target

    The second coordinate

    Return Value

    The bearing to targetin degrees