Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Correct Date Format and Remove Unnecessary Indentation #9

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 37 additions & 25 deletions XLocation/Categories/NSString+Gpx.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,31 +11,43 @@
@implementation NSString (Gpx)

+(NSString *)generateGpxWithFilename:(NSString*) filename latitude:(NSNumber *)lat longitude:(NSNumber *)lng address:(NSString *)address city:(NSString *)city country:(NSString *)country zip:(NSString *)zipCode{
return [NSString stringWithFormat:@"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n\
<gpx\n\
xmlns=\"http://www.topografix.com/GPX/1/1\"\n\
xmlns:gpxx = \"http://www.garmin.com/xmlschemas/GpxExtensions/v3\"\n\
xmlns:xsi = \"http://www.w3.org/2001/XMLSchema-instance\"\n\
xsi:schemaLocation=\"http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd\n\
http://www.garmin.com/xmlschemas/GpxExtensions/v3\n\
http://www8.garmin.com/xmlschemas/GpxExtensions/v3/GpxExtensionsv3.xsd\"\n\
version=\"1.1\"\n\
creator=\"StefanLage\">\n\
<wpt lat=\"%@\" lon=\"%@\">\n\
<time>%@</time>\n\
<name>%@</name>\n\
<extensions>\n\
<gpxx:WaypointExtension>\n\
<gpxx:Address>\n\
<gpxx:StreetAddress>%@</gpxx:StreetAddress>\n\
<gpxx:City>%@</gpxx:City>\n\
<gpxx:Country>%@</gpxx:Country>\n\
<gpxx:PostalCode>%@</gpxx:PostalCode>\n\
</gpxx:Address>\n\
</gpxx:WaypointExtension>\n\
</extensions>\n\
</wpt>\n\
</gpx>", lat, lng, [NSDate new], filename, address, city, country, zipCode];

NSDateFormatter *rfc3339DateFormatter = [[NSDateFormatter alloc] init];
NSLocale *enUSPOSIXLocale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"];

[rfc3339DateFormatter setLocale:enUSPOSIXLocale];
[rfc3339DateFormatter setDateFormat:@"yyyy'-'MM'-'dd'T'HH':'mm':'ss'Z'"];
[rfc3339DateFormatter setTimeZone:[NSTimeZone timeZoneForSecondsFromGMT:0]];

NSString *dateString = [rfc3339DateFormatter stringFromDate:[NSDate new]];

return [NSString stringWithFormat:
@"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n\
<gpx\n\
xmlns=\"http://www.topografix.com/GPX/1/1\"\n\
xmlns:gpxx = \"http://www.garmin.com/xmlschemas/GpxExtensions/v3\"\n\
xmlns:xsi = \"http://www.w3.org/2001/XMLSchema-instance\"\n\
xsi:schemaLocation=\"http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd\n\
http://www.garmin.com/xmlschemas/GpxExtensions/v3\n\
http://www8.garmin.com/xmlschemas/GpxExtensions/v3/GpxExtensionsv3.xsd\"\n\
version=\"1.1\"\n\
creator=\"StefanLage\">\n\
<wpt lat=\"%@\" lon=\"%@\">\n\
<time>%@</time>\n\
<name>%@</name>\n\
<extensions>\n\
<gpxx:WaypointExtension>\n\
<gpxx:Address>\n\
<gpxx:StreetAddress>%@</gpxx:StreetAddress>\n\
<gpxx:City>%@</gpxx:City>\n\
<gpxx:Country>%@</gpxx:Country>\n\
<gpxx:PostalCode>%@</gpxx:PostalCode>\n\
</gpxx:Address>\n\
</gpxx:WaypointExtension>\n\
</extensions>\n\
</wpt>\n\
</gpx>",
lat, lng, dateString, filename, address, city, country, zipCode];
}

@end