Swiftpack.co -  mmllr/GPXKit as Swift Package
Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
mmllr/GPXKit
A library for parsing GPX files, with no dependencies, written in Swift
.package(url: "https://github.com/mmllr/GPXKit.git", from: "1.03")

GPXKit

A library for parsing and exporting gpx files with no dependencies besides Foundation.

Features

  • ☑ Parsing gpx files into a track struct
  • ☑ Exporting a track to a gpx xml
  • ☑ Support for iOS, macOS & watchOS
  • ☑ Optionally removes date and time from exported gpx for keeping privacy
  • ☑ Combine support
  • ☑ Heightmap, geobounds, distance and elevation information for an imported track
  • ☑ Test coverage

Installation

To use the GPXKit library in a SwiftPM project, add the following line to the dependencies in your Package.swift file:

.package(url: "https://github.com/mmllr/GPXKit", from: "1.2.6"),

Usage examples

Importing a track

import GPXKit

let parser = GPXFileParser(xmlString: xml)
    switch parser.parse() {
    case .success(let track):
        doSomethingWith(track)
    case .failure(let error):
        parseError = error
    }
...
func doSomethingWith(_ track: GPXTrack) {
    let formatter = MeasurementFormatter()
    formatter.unitStyle = .short
    formatter.unitOptions = .naturalScale
    formatter.numberFormatter.maximumFractionDigits = 1
    let trackGraph = track.graph
    print("Track length: \(formatter.string(from: Measurement<UnitLength>(value: trackGraph.distance, unit: .meters)))")
    print("Track elevation: \(formatter.string(from: Measurement<UnitLength>(value: trackGraph.elevationGain, unit: .meters)))")
    
    for point in track.trackPoints {
        print("Lat: \(point.coordinate.latitude), lon: \(point.coordinate.longitude)")
    }
}

Exporting a track

import GPXKit
let track: GPXTrack = ...
let exporter = GPXExporter(track: track, shouldExportDate: false)
print(exporter.xmlString)

Combine integration

import Combine
import GPXKit

let url = /// url with gpx
GPXFileParser.load(from: url)
   .publisher
   .map { track in
      // do something with parsed track 
   }

See tests for more usage examples.

Documentation

Project documentation is available at GitHub Pages

Run the following commands from the projects root to generate the documentation:

[sudo] gem install jazzy
jazzy

Browse the documention under the doc folder.

Contributing

Contributions to this project will be more than welcomed. Feel free to add a pull request or open an issue. If you require a feature that has yet to be available, do open an issue, describing why and what the feature could bring and how it would help you!

GitHub

link
Stars: 2
Last commit: 1 week ago

Ad: Job Offers

iOS Software Engineer @ Perry Street Software
Perry Street Software is Jack’d and SCRUFF. We are two of the world’s largest gay, bi, trans and queer social dating apps on iOS and Android. Our brands reach more than 20 million members worldwide so members can connect, meet and express themselves on a platform that prioritizes privacy and security. We invest heavily into SwiftUI and using Swift Packages to modularize the codebase.

Release Notes

15 weeks ago

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API