3

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?

VansFannel
  • 45,055
  • 107
  • 359
  • 626
  • If I have set of coordinates, can they be converterd in GPX file? – chatur Jan 04 '12 at 05:59
  • @chatur yes they can be. – krammer Jan 04 '12 at 09:37
  • @krammer, thanks for your response. Actually along with coordinates there is other information also(description of coordinates etc). I tried to find appropriate tutorial for creating GPX file but could not find it. Can you please point any resource that will help me? – chatur Jan 04 '12 at 09:41

4 Answers4

4

Have a look at: http://terrabrowser.googlecode.com/svn/trunk/

There you will find GPSFileParser.m and GPSFileParser.h which may help you.

krammer
  • 2,598
  • 2
  • 25
  • 46
3

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).

Bryce Groff
  • 43
  • 1
  • 7
1

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.

Stewart Macdonald
  • 2,062
  • 24
  • 27
1

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.

Dave Robertson
  • 431
  • 3
  • 6
  • 3
    There is now an open source library for parsing GPX under iOS, the [iOS GPX Framework](http://gpxframework.com/). The source is on [Watanabe Toshinori's github site](https://github.com/FLCLjp) along with a KML library and example apps showing how to use the libraries. – Dave Robertson Jun 21 '12 at 04:32
  • 1
    Good Option.. but it seems it does not support 64-Bit architecture. Please correct me if i am wrong :) – Gaurav Jul 15 '14 at 11:59