I can't开发者_JS百科 seem to convert two lat and LNG to a string. By the time I convert to degrees and back to a string I get large numbers like 999737 for what should be 2 miles or less away.
OK works!
Here is how you can convert between double -> string & back from string -> double
//Defining Latitude & Longitude
NSNumber *latitude = [NSNumber numberWithDouble:31.5497226715];
NSNumber *longitude = [NSNumber numberWithDouble:74.3436126709];
NSLog(@"Origional > Lat: %.10f, Lng: %.10f", [latitude doubleValue], [longitude doubleValue]);
//Conversion to string
NSString *latitudeStr = [latitude stringValue];
NSString *longitudeStr = [longitude stringValue];
NSLog(@"String > Lat: %@, Lng: %@", latitudeStr, longitudeStr);
//String to double
NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init];
[numberFormatter setNumberStyle:NSNumberFormatterDecimalStyle];
NSNumber *latitudeFromStr = [numberFormatter numberFromString:latitudeStr];
NSNumber *longitudeFromStr = [numberFormatter numberFromString:longitudeStr];
[numberFormatter release];
NSLog(@"Back from string > Lat: %.10f, Lng: %.10f", [latitudeFromStr doubleValue], [longitudeFromStr doubleValue]);
精彩评论