Created
February 1, 2013 03:22
-
-
Save mmorey/4688909 to your computer and use it in GitHub Desktop.
Converts NOAA string into a CLLocationCoordinate2D coordinate
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (CLLocationCoordinate2D)locationFromString:(NSString *)locationString{ | |
CLLocationCoordinate2D coordinate; | |
// Extract individual components | |
NSMutableArray *locationColumns = [NSMutableArray arrayWithArray: | |
[locationString componentsSeparatedByCharactersInSet: | |
[NSCharacterSet whitespaceCharacterSet]]]; | |
// Remove empty objects | |
[locationColumns removeObject:@""]; | |
// Build latitude prefix | |
NSString *latitudePrefix; | |
if(![[locationColumns objectAtIndex:1] isEqualToString:@"N"]){ | |
latitudePrefix = @"-"; | |
} else{ | |
latitudePrefix = @""; | |
} | |
// Build longitude prefix | |
NSString *longitudePrefix; | |
if(![[locationColumns objectAtIndex:3] isEqualToString:@"E"]){ | |
longitudePrefix = @"-"; | |
} else{ | |
longitudePrefix = @""; | |
} | |
// Create and return coordinate | |
coordinate.latitude = [[latitudePrefix stringByAppendingString:[locationColumns objectAtIndex:0]] doubleValue]; | |
coordinate.longitude = [[longitudePrefix stringByAppendingString:[locationColumns objectAtIndex:2]] doubleValue]; | |
return coordinate; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment