{"id":23150997,"url":"https://github.com/anconaesselmann/swiftgpx","last_synced_at":"2025-08-17T19:32:13.292Z","repository":{"id":55521923,"uuid":"117532952","full_name":"anconaesselmann/SwiftGpx","owner":"anconaesselmann","description":"SwiftGpx is a small library for reading and writing GPX files.","archived":false,"fork":false,"pushed_at":"2021-09-13T22:23:05.000Z","size":218,"stargazers_count":5,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-08-14T02:57:20.770Z","etag":null,"topics":["cllocation","corelocation","gpx","ios","mapkit","swift"],"latest_commit_sha":null,"homepage":"","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/anconaesselmann.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-01-15T10:45:24.000Z","updated_at":"2025-05-05T06:58:57.000Z","dependencies_parsed_at":"2022-08-15T02:20:33.879Z","dependency_job_id":null,"html_url":"https://github.com/anconaesselmann/SwiftGpx","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/anconaesselmann/SwiftGpx","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anconaesselmann%2FSwiftGpx","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anconaesselmann%2FSwiftGpx/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anconaesselmann%2FSwiftGpx/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anconaesselmann%2FSwiftGpx/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/anconaesselmann","download_url":"https://codeload.github.com/anconaesselmann/SwiftGpx/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anconaesselmann%2FSwiftGpx/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":270898273,"owners_count":24664700,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-17T02:00:09.016Z","response_time":129,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cllocation","corelocation","gpx","ios","mapkit","swift"],"created_at":"2024-12-17T18:19:44.936Z","updated_at":"2025-08-17T19:32:13.005Z","avatar_url":"https://github.com/anconaesselmann.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# SwiftGpx\n\n[![CI Status](http://img.shields.io/travis/anconaesselmann/SwiftGpx.svg?style=flat)](https://travis-ci.org/anconaesselmann/SwiftGpx)\n[![Version](https://img.shields.io/cocoapods/v/SwiftGpx.svg?style=flat)](http://cocoapods.org/pods/SwiftGpx)\n[![License](https://img.shields.io/cocoapods/l/SwiftGpx.svg?style=flat)](http://cocoapods.org/pods/SwiftGpx)\n[![Platform](https://img.shields.io/cocoapods/p/SwiftGpx.svg?style=flat)](http://cocoapods.org/pods/SwiftGpx)\n\nSwiftGpx is a library for parsing and writing [GPX](https://www.topografix.com/gpx.asp) data.\n\nSwiftGpx powers [GPX File Editor](https://apps.apple.com/us/app/gpx-file-editor/id1583908804), which is available for iPhone in the App Store.\n\n## Example\n\nTo run the example playground clone the repo, run `pod install` in the `Example` directory and open the `Example.xcworkspace` workspace. The `Example` playground (first element in the Project Navigator) contains all the examples from below.\n\n\nImport `SwiftGpx`\n```swift\nimport SwiftGpx\n```\nsome examples below reqire you to import\n```swift\nimport CoreLocation\n```\n\n### Instantiating [GPX](https://www.topografix.com/gpx.asp) objects...\n\n...with an `Array` of `CLLocation` instances:\n```swift\nlet locations: [CLLocation] = [\n    CLLocation(lat: 38.1237270, lon: -119.4670500, alt: 2899.8, timestamp: \"2021-06-03T20:25:26Z\"),\n    CLLocation(lat: 38.1237330, lon: -119.4670490, alt: 2899.8, timestamp: \"2021-06-03T20:25:27Z\"),\n    CLLocation(lat: 38.1237360, lon: -119.4670510, alt: 2899.8, timestamp: \"2021-06-03T20:25:28Z\"),\n    CLLocation(lat: 38.1237360, lon: -119.4670500, alt: 2899.8, timestamp: \"2021-06-03T20:25:29Z\"),\n    CLLocation(lat: 38.1237360, lon: -119.4670500, alt: 2899.8, timestamp: \"2021-06-03T20:25:30Z\"),\n    CLLocation(lat: 38.1237360, lon: -119.4670510, alt: 2899.8, timestamp: \"2021-06-03T20:25:31Z\")\n].compactMap { $0 }\n\nlet gpx = GPX(name: \"My Track\", locations: locations)\n```\n\n...with the xml contents of a GPX file\n```swift\nlet gpxString = \"\"\"\n\u003c?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\" ?\u003e\n\u003cgpx\n    xmlns=\"http://www.topografix.com/GPX/1/1\" creator=\"SwiftGpx by Axel Ancona Esselmann\" version=\"1.1\"\n    xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd\"\u003e\n    \u003ctrk\u003e\n        \u003cname\u003eMy Track\u003c/name\u003e\n        \u003ctrkseg\u003e\n            \u003ctrkpt lat=\"38.123727\" lon=\"-119.46705\"\u003e\n                \u003cele\u003e2899.8\u003c/ele\u003e\n                \u003ctime\u003e2021-06-03T20:25:26Z\u003c/time\u003e\n            \u003c/trkpt\u003e\n            \u003ctrkpt lat=\"38.123733\" lon=\"-119.467049\"\u003e\n                \u003cele\u003e2899.8\u003c/ele\u003e\n                \u003ctime\u003e2021-06-03T20:25:27Z\u003c/time\u003e\n            \u003c/trkpt\u003e\n        \u003c/trkseg\u003e\n        \u003ctrkseg\u003e\n            \u003ctrkpt lat=\"38.123736\" lon=\"-119.467051\"\u003e\n                \u003cele\u003e2899.8\u003c/ele\u003e\n                \u003ctime\u003e2021-06-03T20:25:28Z\u003c/time\u003e\n            \u003c/trkpt\u003e\n            \u003ctrkpt lat=\"38.123736\" lon=\"-119.46705\"\u003e\n                \u003cele\u003e2899.8\u003c/ele\u003e\n                \u003ctime\u003e2021-06-03T20:25:29Z\u003c/time\u003e\n            \u003c/trkpt\u003e\n        \u003c/trkseg\u003e\n    \u003c/trk\u003e\n\u003c/gpx\u003e\n\"\"\"\n\nlet gpx = GPX(xmlString: gpxString)\n```\n\n...with the name of a file that is located in the `Bundle`\n```swift\nlet gpx = GPX(fileName: \"example\", fileExtension: \"gpx\")\n```\n\n...with a local file resource\n```swift\nif let localResource = Bundle.main.url(forResource: \"example\", withExtension: \"gpx\") {\n    let gpx = GPX(localResource: localResource)\n    ...\n}\n```\n\n### Converting `GPX` content to...\n\n...a GPX `String`\n```swift\nlet gpx = GPX(name: \"My Track\", locations: locations)\nlet xmlString = gpx.xmlString\n```\n\n... `Data`, which is encoded to be stored or transmitted as a GPX file\n```swift\nlet gpx = GPX(name: \"My Track\", locations: locations)\nlet xmlData = gpx.data\n```\n\n### Serializing/Deserializing using Codabl\n\nthe `JSONEncoder` settings below will produce output like the following:\n```json\n{\n  \"name\" : \"My Track\",\n  \"track_segments\" : [\n    [\n      {\n        \"lat\" : 38.123727000000002,\n        \"lon\" : -119.46705,\n        \"ele\" : 2899.8000000000002,\n        \"date\" : \"2021-06-03T20:25:26Z\"\n      },\n      {\n        \"lat\" : 38.123733000000001,\n        \"lon\" : -119.467049,\n        \"ele\" : 2899.8000000000002,\n        \"date\" : \"2021-06-03T20:25:27Z\"\n      }\n    ],\n    [\n      {\n        \"lat\" : 38.123736000000001,\n        \"lon\" : -119.46705,\n        \"ele\" : 2899.8000000000002,\n        \"date\" : \"2021-06-03T20:25:29Z\"\n      },\n      {\n        \"lat\" : 38.123736000000001,\n        \"lon\" : -119.46705,\n        \"ele\" : 2899.8000000000002,\n        \"date\" : \"2021-06-03T20:25:30Z\"\n      }\n    ]\n  ]\n}\n```\n\nEncoding using JSONEncoder\n```swift\nlet gpx = GPX(name: \"My Track\", locations: locations)\n\nlet encoder = JSONEncoder()\nencoder.dateEncodingStrategy = .iso8601\nencoder.keyEncodingStrategy = .convertToSnakeCase\nencoder.outputFormatting = [.prettyPrinted]\nlet encoded = try encoder.encode(gpx)\nlet encodedString = String(data: encoded, encoding: .utf8)\n```\n\nDecoding using JSONDecoder\n```swift\nlet decoder = JSONDecoder()\ndecoder.dateDecodingStrategy = .iso8601\ndecoder.keyDecodingStrategy = .convertFromSnakeCase\n// uses the encoded data from the previous example\nlet gpxFromJson = try decoder.decode(GPX.self, from: encoded) \n```\n\n## Serializing into a dictionary that keeps the structure of the XML intact\n\nthe `gpxJson` propperty will produce a dictionary that can be serialized to look like the following:\n```json\n{\n    \"gpx\": {\n        \"name\": \"My Track\",\n        \"trkseg_elements\": [\n            [\n                {\n                    \"lon\": -119.46705,\n                    \"lat\": 38.123727000000002,\n                    \"ele\": 2899.8000000000002,\n                    \"time\": \"2021-06-03T13:25:26-0700\"\n                },\n                {\n                    \"time\": \"2021-06-03T13:25:27-0700\",\n                    \"lon\": -119.467049,\n                    \"lat\": 38.123733000000001,\n                    \"ele\": 2899.8000000000002\n                }\n            ]\n        ]\n    }\n}\n```\n\n```swift\nlet gpx = GPX(name: \"My Track\", locations: locations)\nlet dictionary: [String: Any] = gpx.gpxJson\n```\n\nYou can get a JSON string using\n```swift\nlet gpx = GPX(name: \"My Track\", locations: locations)\nlet data = try JSONSerialization.data(withJSONObject: gpx.gpxJson, options: [.prettyPrinted])\nlet jsonString = String(data: data, encoding: .utf8)\n```\n\n## Installation\n\nSwiftGpx is available through [CocoaPods](http://cocoapods.org). To install\nit, simply add the following line to your Podfile:\n\n```ruby\npod 'SwiftGpx'\n```\n\n## Author\n\nanconaesselmann, axel@anconaesselmann.com\n\n## License\n\nSwiftGpx is available under the MIT license. See the LICENSE file for more info.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fanconaesselmann%2Fswiftgpx","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fanconaesselmann%2Fswiftgpx","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fanconaesselmann%2Fswiftgpx/lists"}