GPX解析器或GPX文档

3

我正在开发一个iOS 5应用程序。

我想开发一个GPX解析器,但我想知道是否已经有开发过了。

您知道是否有Objective-c GPX解析器吗?


如果我有一组坐标,它们可以转换成GPX文件吗? - chatur
@chatur 是的,它们可以。 - krammer
@krammer,感谢您的回复。实际上除了坐标之外,还有其他信息(如坐标的描述等)。我尝试寻找适当的教程来创建GPX文件,但没有找到。您能否指出任何可以帮助我的资源? - chatur
4个回答

4

3

我已经在开发 gpx-api 一段时间了。它可以读取gpx文件,并拥有一个可用的数据模型(依据我的个人看法)。


1

目前,Objective-C 没有特定的 GPX 解析器。

不过这并不是问题,因为 GPX 只是 XML,所以您可以使用任何 XML 解析器来处理 GPX 数据。请参阅Ray Wenderlich's tutorial on iOS XML parsers 了解一些示例。


3
现在有一个用于iOS下解析GPX的开源库,名为iOS GPX Framework。源代码位于Watanabe Toshinori的github网站,其中还包括一个KML库和示例应用程序,展示如何使用这些库。 - Dave Robertson
1
不错的选择..但似乎它不支持64位架构。如果我错了,请纠正我 :) - Gaurav

1
我意识到这是一个老问题,但我刚开始使用这个GPX解析器:

https://github.com/patricks/gpx-parser-cocoa

这是从这个分支派生出来的:

https://github.com/fousa/gpx-parser-ios

下面是我正在使用的代码。它假定您已经将一个IBOutlet(self.theMapView)连接到您的MKMapView,已设置代理并将MapKit框架添加到您的目标中,并且您在项目中有一个有效的gpx文件(称为test-gpx.gpx)。我正在使用这个Mac应用程序中,但我认为该代码也可以在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;

}

下面提到的iOS GPX Framework,看起来很不错,所以我可能会在某个时候转投它。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接