Skip to content

Instantly share code, notes, and snippets.

View valeriyvan's full-sized avatar
🎯
Focusing

Valeriy Van valeriyvan

🎯
Focusing
View GitHub Profile
@valeriyvan
valeriyvan / DMSToDecimal
Last active August 19, 2019 12:35
Geographic coordinate conversion from NSString in DMS format into decimal in CLLocationDegrees (aka double).http://en.wikipedia.org/wiki/Geographic_coordinate_conversion43° 36' 15.894" N => 43.60442
// http://en.wikipedia.org/wiki/Geographic_coordinate_conversion
// 43° 36' 15.894" N => 43.60442
#import "DMSToDecimal.h"
BOOL DMSToDecimal(NSString* dms, CLLocationDegrees *decimal) {
CLLocationDegrees degres=0, minutes=0, seconds=0;
NSScanner *scanner = [NSScanner scannerWithString:dms];
scanner.charactersToBeSkipped = [NSCharacterSet whitespaceAndNewlineCharacterSet];
if (![scanner scanDouble:&degres]) {