问题
I'm developing an iOS 5 application.
I want to develop a GPX parser but I'm wondering if there is one developed before I start to developing it.
Do you know if there is an Objective-c GPX parser?
回答1:
Have a look at: http://terrabrowser.googlecode.com/svn/trunk/
There you will find GPSFileParser.m and GPSFileParser.h which may help you.
回答2:
I have been working on the gpx-api for a little while. It will read gpx files and has a data model that is useable (in my opinion).
回答3:
There is no specific GPX parser for Obejective-C at present.
This is not really a problem though since GPX is just XML, so you can use any XML parser to work with GPX data. Take a look at Ray Wenderlich's tutorial on iOS XML parsers for some examples.
回答4:
I realise this is an old question, but I've just started using this GPX parser:
https://github.com/patricks/gpx-parser-cocoa
which is forked from this one:
https://github.com/fousa/gpx-parser-ios
Below is the code I'm using. It assumes you've got an IBOutlet (self.theMapView) hooked up to your MKMapView, that you've set the delegate and added the MapKit framework to your target, and that you've got a valid gpx file (called test-gpx.gpx) in your project. I'm using this in a Mac app, but I think the code will also work in iOS.
- (void)parseGPX {
NSString *gpxFilePath = [[NSBundle mainBundle] pathForResource:@"test-gpx" ofType:@"gpx"];
NSData *fileData = [NSData dataWithContentsOfFile:gpxFilePath];
[GPXParser parse:fileData completion:^(BOOL success, GPX *gpx) {
// success indicates completion
// gpx is the parsed file
if (success) {
NSLog(@"GPX success: %@", gpx);
NSLog(@"GPX filename: %@", gpx.filename);
NSLog(@"GPX waypoints: %@", gpx.waypoints);
NSLog(@"GPX routes: %@", gpx.routes);
NSLog(@"GPX tracks: %@", gpx.tracks);
[self.theMapView removeAnnotations:self.theMapView.annotations];
for (Waypoint *thisPoint in gpx.waypoints) {
// add this waypoint to the map
MKPointAnnotation *thisRecord = [[MKPointAnnotation alloc] init];
thisRecord.coordinate = thisPoint.coordinate;
thisRecord.title = thisPoint.name;
[self.theMapView addAnnotation:thisRecord];
}
for (Track *thisTrack in gpx.tracks) {
// add this track to the map
[self.theMapView addOverlay:thisTrack.path];
}
[self.theMapView setRegion:[self.theMapView regionThatFits:gpx.region] animated:YES];
} else {
NSLog(@"GPX fail for file: %@", gpxFilePath);
}
}];
}
- (MKOverlayRenderer*)mapView:(MKMapView*)mapView rendererForOverlay:(id <MKOverlay>)overlay {
MKPolylineRenderer* lineView = [[MKPolylineRenderer alloc] initWithPolyline:overlay];
lineView.strokeColor = [NSColor orangeColor];
lineView.lineWidth = 7;
return lineView;
}
The iOS GPX Framework mentioned by @Dave Robertson below looks good, so I might switch over to that at some point.
来源:https://stackoverflow.com/questions/8639137/gpx-parser-or-gpx-documentation