Gpx 解析器或 GPX 文档

发布于 2024-12-22 17:28:46 字数 111 浏览 5 评论 0原文

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

我想开发一个 GPX 解析器,但我想知道在我开始开发它之前是否已经开发了一个。

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

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

猥︴琐丶欲为 2024-12-29 17:28:46

看看:
http://terrabrowser.googlecode.com/svn/trunk/

在这里您可以找到 GPSFileParser。 m 和 GPSFileParser.h 可能对您有帮助。

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

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

我不会写诗 2024-12-29 17:28:46

我已经在 gpx-api 上工作了一段时间。它将读取 gpx 文件并具有可用的数据模型(在我看来)。

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

酒几许 2024-12-29 17:28:46

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

但这并不是真正的问题,因为 GPX 只是 XML,因此您可以使用任何 XML 解析器来处理 GPX 数据。看看 Ray Wenderlich 有关 iOS XML 解析器的教程 中提供了一些示例。

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.

命硬 2024-12-29 17:28:46

我意识到这是一个老问题,但我刚刚开始使用这个 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;

}

下面 @Dave Robertson 提到的 iOS GPX Framework 看起来不错,所以我可能会切换到那在某个时刻。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文