-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTLGPXWaypoint.m
121 lines (107 loc) · 3.47 KB
/
TLGPXWaypoint.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
//
// TLGPXWaypoint.m
// Mercatalog
//
// Created by Nathan Vander Wilt on 3/17/08.
// Copyright 2008 Calf Trail Software, LLC. All rights reserved.
//
#import "TLGPXWaypoint.h"
@implementation TLGPXWaypoint
- (id)initWithParent:(TLGPXNode*)theParent
forElement:(NSString*)elementName
namespaceURI:(NSString*)namespaceURI
qualifiedName:(NSString*)qualifiedName
attributes:(NSDictionary*)attributes
{
self = [super initWithParent:theParent
forElement:elementName
namespaceURI:namespaceURI
qualifiedName:qualifiedName
attributes:attributes];
if (self) {
coordinate.lat = [[attributes valueForKey:@"lat"] doubleValue];
coordinate.lon = [[attributes valueForKey:@"lon"] doubleValue];
elevation = TLCoordinateAltitudeUnknown;
}
return self;
}
- (void)dealloc {
[time release];
[name release];
[super dealloc];
}
#pragma mark Parsing out of XML
- (void)parser:(NSXMLParser*)parser didStartElement:(NSString*)elementName
namespaceURI:(NSString*)namespaceURI
qualifiedName:(NSString*)qualifiedName
attributes:(NSDictionary*)attributeDict
{
(void)parser;
(void)namespaceURI;
(void)qualifiedName;
(void)attributeDict;
if ([elementName isEqualToString:@"time"] ||
[elementName isEqualToString:@"name"] ||
[elementName isEqualToString:@"ele"] ||
[elementName isEqualToString:@"hdop"] ||
[elementName isEqualToString:@"vdop"] ||
[elementName isEqualToString:@"pdop"])
{
[self setGatheringCharacters:YES];
}
}
static NSDate* TLNSDateFromStandardString(NSString* str) {
NSDateFormatter* formatISO8601 = [[[NSDateFormatter alloc] init] autorelease];
[formatISO8601 setTimeStyle:NSDateFormatterFullStyle];
[formatISO8601 setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss'Z'"];
NSDate* date = [formatISO8601 dateFromString:str];
if (!date) {
NSDateFormatter* formatISO8601milliseconds = [[[NSDateFormatter alloc] init] autorelease];
[formatISO8601milliseconds setTimeStyle:NSDateFormatterFullStyle];
[formatISO8601milliseconds setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss.SSSS'Z'"];
date = [formatISO8601milliseconds dateFromString:str];
}
return date;
}
- (void)parser:(NSXMLParser*)parser didEndElement:(NSString*)elementName
namespaceURI:(NSString*)namespaceURI
qualifiedName:(NSString*)qualifiedName
{
if ([elementName isEqualToString:@"time"]) {
time = [TLNSDateFromStandardString([self gatheredCharacters]) copy];
if (!time) NSLog(@"Could not convert string '%@' to a date!", [self gatheredCharacters]);
[self setGatheringCharacters:NO];
}
else if ([elementName isEqualToString:@"ele"]) {
elevation = [[self gatheredCharacters] doubleValue];
[self setGatheringCharacters:NO];
}
else if ([elementName isEqualToString:@"name"]) {
name = [[self gatheredCharacters] copy];
[self setGatheringCharacters:NO];
}
else if ([elementName isEqualToString:@"hdop"]) {
horizontalDOP = [[self gatheredCharacters] doubleValue];
[self setGatheringCharacters:NO];
}
else if ([elementName isEqualToString:@"vdop"]) {
verticalDOP = [[self gatheredCharacters] doubleValue];
[self setGatheringCharacters:NO];
}
else if ([elementName isEqualToString:@"pdop"]) {
positionDOP = [[self gatheredCharacters] doubleValue];
[self setGatheringCharacters:NO];
}
else {
[super parser:parser didEndElement:elementName namespaceURI:namespaceURI qualifiedName:qualifiedName];
}
}
#pragma mark Accessors
@synthesize name;
@synthesize time;
@synthesize coordinate;
@synthesize elevation;
@synthesize horizontalDOP;
@synthesize verticalDOP;
@synthesize positionDOP;
@end