https://github.com/sun-jiao/geoxml
A Dart library for loading, manipulating, and saving GPS data in XML format, including GPX and KML.
https://github.com/sun-jiao/geoxml
dart-library geocoding geolocation gpx kml xml
Last synced: about 1 month ago
JSON representation
A Dart library for loading, manipulating, and saving GPS data in XML format, including GPX and KML.
- Host: GitHub
- URL: https://github.com/sun-jiao/geoxml
- Owner: sun-jiao
- License: apache-2.0
- Created: 2023-05-12T08:01:28.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2025-03-29T14:04:02.000Z (about 1 year ago)
- Last Synced: 2025-03-29T14:31:31.161Z (about 1 year ago)
- Topics: dart-library, geocoding, geolocation, gpx, kml, xml
- Language: Dart
- Homepage: https://pub.dev/packages/geoxml
- Size: 544 KB
- Stars: 41
- Watchers: 2
- Forks: 7
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
geoxml
======
[](https://pub.dev/packages/geoxml)
[](https://coveralls.io/github/sun-jiao/geoxml?branch=main)
[](https://github.com/sun-jiao/geoxml/issues)
[](https://github.com/sun-jiao/geoxml/network)
[](https://github.com/sun-jiao/geoxml/stargazers)
[](https://raw.githubusercontent.com/sun-jiao/geoxml/master/LICENSE)
A Dart library for loading, manipulating, and saving GPS data in XML format, including GPX and KML.
GPX is a light-weight XML data format for the interchange of GPS data - waypoints, routes,
and tracks. KML is a XML data format used to display geographic data in an Earth browser
such as Google Earth.
The GPX document: https://www.topografix.com/gpx.asp.
And for KML, see https://developers.google.com/kml/ .
The project is originally authored by @kb0 with others, thanks for their works.
## Limitations
This is just an initial version of the package. There are still some limitations:
- No support for GPX 1.0.
- Doesn't validate schema declarations.
- Some KML elements and attributes are not implemented.
- The conversion between GPX and KML is lossy. For example, GPX does not contain style information such as color, while KML can not tell the difference between routes and tracks. Converting a GPX to KML and then converting it back cannot obtain the original GPX.
## Getting Started
In your dart/flutter project add the dependency:
```
dependencies:
...
geoxml: ^2.5.3
```
### Reading GPX
To read GPX input use the GpxReader object and function `GeoXml.fromGpxString(String input)`:
```dart
import 'package:geoxml/geoxml.dart';
main() async {
// create gpx from xml string
var xmlGpx = await GeoXml.fromGpxString(''
''
'10.0Monte QuemadoArgentina'
'');
print(xmlGpx);
print(xmlGpx.wpts);
}
```
To read GPX from a `Stream`:
```dart
import 'package:geoxml/geoxml.dart';
main() async {
// create gpx from xml string stream
final stream = File('test/assets/wpt.gpx').openRead()
.transform(utf8.decoder);
final xmlGpx = await GeoXml.fromGpxStream(stream);
print(xmlGpx);
print(xmlGpx.wpts);
}
```
### Writing GPX
To write object to GPX use the method `asGpxString(Gpx gpx, {bool pretty = false})`:
```dart
import 'package:geoxml/geoxml.dart';
main() {
// create gpx object
var gpx = Gpx();
gpx.creator = "dart-gpx library";
gpx.wpts = [
Wpt(lat: 36.62, lon: 101.77, ele: 10.0, name: 'Xining', desc: 'China'),
];
// generate xml string
var gpxString = gpx.asGpxString(pretty: true);
print(gpxString);
}
```
### Reading KML
To read KML input use the KmlReader object and function `GeoXml.fromKmlString(String input)`:
```dart
import 'package:geoxml/geoxml.dart';
main() async {
// create gpx from xml string
var xmlKml = await GeoXml.fromKmlString(' '
'Monte Quemado'
'Argentina '
'absolute'
'-62.8666,-25.7996,10.0'
'');
print(xmlKml);
print(xmlKml.wpts);
}
```
To read KML from a `Stream`:
```dart
import 'package:geoxml/geoxml.dart';
main() async {
// create gpx from xml string stream
final stream = File('test/assets/wpt.kml').openRead()
.transform(utf8.decoder);
final kml = await GeoXml.fromKmlStream(stream);
print(xmlGpx);
print(xmlGpx.wpts);
}
```
### Writing KML
To export object to KML use the method `asKmlString({bool pretty = false})`:
```dart
import 'package:geoxml/geoxml.dart';
main() {
// create gpx object
var geoXml = GeoXml();
geoXml.creator = "dart geoxml library";
geoXml.wpts = [
Wpt(lat: 36.62, lon: 101.77, ele: 10.0, name: 'Xining', desc: 'China'),
];
// generate xml string
var kmlString = geoXml.asKmlString(pretty: true);
print(kmlString);
// generate xml string with altitude mode - clampToGround
var kmlString = KmlWriter(altitudeMode: AltitudeMode.clampToGround)
.asString(gpx, pretty: true);
print(kmlString);
}
```
## Features and bugs
Please file feature requests and bugs at the [issue tracker][tracker].
[tracker]: https://github.com/sun-jiao/geoxml/issues
### License
The Apache 2.0 License, see [LICENSE](https://github.com/sun-jiao/geoxml/raw/main/LICENSE).