GPXRoot

public final class GPXRoot : GPXElement, Codable

Creation of a GPX file or GPX formatted string starts here

GPXRoot holds all metadata, waypoints, tracks, routes and extensions types together before being packaged as a GPX file, or formatted as per GPX schema’s requirements.

GPX v1.1 Namespaces

  • for initializing without a creator name

    It will initialize with the creator name set to its defaults.

    Declaration

    Swift

    public required init()
  • for initializing with a creator name

    Declaration

    Swift

    public init(creator: String)

    Parameters

    creator

    name of your app, or whichever product that ends up generating a GPX file

  • Initialize if planned to use with extensions

    Declaration

    Swift

    public init(withExtensionAttributes attributes: [String : String], schemaLocation: String)

    Parameters

    attributes

    Extension attributes to be placed in the gpx tag header. Key should be name of attribute, while Value contains the value of the attribute.

    schemaLocation

    Location/Website of the extension schema

  • Initialize if planned to use with extensions, with creator name.

    Declaration

    Swift

    public convenience init(withExtensionAttributes attributes: [String : String], schemaLocation: String, creator: String)
  • for saving newly tracked data straight to a GPX file in a directory

    Throws

    An error if GPX file fails to write at location for whichever reason.

    Declaration

    Swift

    public func outputToFile(saveAt location: URL, fileName: String) throws

    Parameters

    location

    A URL where you wish to have the GPX file saved at.

    fileName

    The name of the file which you wish to save as, without extension.

  • Initializes a new waypoint which is also added to GPXRoot automatically

    A waypoint is initialized with latitude and longitude, then added into the array of waypoints in this GPXRoot.

    Warning

    This method is not recommended. It is recommended that you initialize a waypoint first, configure it, and use method add(waypoint:) instead.

    Declaration

    Swift

    public func newWaypointWith(latitude: Double, longitude: Double) -> GPXWaypoint

    Parameters

    latitude

    Waypoint’s latitude in Double or CLLocationDegrees

    longitude

    Waypoint’s latitude in Double or CLLocationDegrees

    Return Value

    A GPXWaypoint object.

  • Add a pre-initialized and configured waypoint to GPXRoot

    Declaration

    Swift

    public func add(waypoint: GPXWaypoint?)

    Parameters

    waypoint

    The waypoint that you wish to include in GPXRoot

  • Add an array of pre-initialized and configured waypoints to GPXRoot

    Declaration

    Swift

    public func add(waypoints: [GPXWaypoint])

    Parameters

    waypoints

    Array of waypoints that you wish to include in GPXRoot

  • Removes an already added waypoint from GPXRoot

    Declaration

    Swift

    public func remove(waypoint: GPXWaypoint)

    Parameters

    waypoint

    The waypoint that you wish to remove from GPXRoot

  • Remove waypoint from root’s array at index.

    Declaration

    Swift

    public func remove(WaypointAtIndex index: Int)
  • Initializes a new route which is also added to GPXRoot automatically

    A route is initialized, then added into the array of routes in this GPXRoot.

    Warning

    This method is not recommended. It is recommended that you initialize a route first, configure it, and use method add(route:) instead.

    Declaration

    Swift

    public func newRoute() -> GPXRoute

    Return Value

    A GPXRoute object.

  • Add a pre-initialized and configured route to GPXRoot

    Declaration

    Swift

    public func add(route: GPXRoute?)

    Parameters

    route

    The route that you wish to include in GPXRoot

  • Add an array of pre-initialized and configured routes to GPXRoot

    Declaration

    Swift

    public func add(routes: [GPXRoute])

    Parameters

    routes

    The array of routes that you wish to include in GPXRoot

  • Removes an already added waypoint from GPXRoot

    Declaration

    Swift

    public func remove(route: GPXRoute)

    Parameters

    route

    The route that you wish to remove from GPXRoot

  • Initializes a new track which is also added to GPXRoot automatically

    A track is initialized, then added into the array of tracks in this GPXRoot.

    Warning

    This method is not recommended. It is recommended that you initialize a track first, configure it, and use method add(track:) instead.

    Declaration

    Swift

    public func newTrack() -> GPXTrack

    Return Value

    A GPXTrack object.

  • Add a pre-initialized and configured track to GPXRoot

    Declaration

    Swift

    public func add(track: GPXTrack?)

    Parameters

    track

    The track that you wish to include in GPXRoot

  • Add an array of pre-initialized and configured tracks to GPXRoot

    Declaration

    Swift

    public func add(tracks: [GPXTrack])

    Parameters

    tracks

    The array of tracks that you wish to include in GPXRoot

  • Removes an already added track from GPXRoot

    Declaration

    Swift

    public func remove(track: GPXTrack)

    Parameters

    track

    The track that you wish to remove from GPXRoot