Using http://maps.google.com/maps/geo?q=…. return latitude and longitude like those :
48.8616441,2.3448885
in a return string like this one :
200,8,48.8616441,2.3448885
When parsed a into a function that returns a CLLocationCoordinate2D :
NSArray* listItems = [locationString componentsSeparatedByString:@","];
CLLocationDegrees latitude = kInexistantLatitude;
CLLocationDegrees longitude = kInexistantLongitude;
if([listItems count] >= 4 && [[listItems objectAtIndex:0] isEqualToString:@"200"]) {
latitude = [[listItems objectAtIndex:2] doubleValue];
longitude = [[listItems objectAtIndex:3] doubleValue];
}
CLLocationCoordinate2D location;
location.latitude = latitude;
location.longitude = longitude;
return location;
it gives into the debugger :
latitude = 48.861644099999999
longitude = 2.3448885000000002
I store many items like this one into an array, and at the end, I parse the array to write them into a plist file as dictionary items ( tag) (I use a NSString appendFormat that gives, like a NSLog) :
NSLog(@"%f %f", location.latitude, location.longitude);
48.861644 2.344889
At some moment, I will load that dictionary, and I will store that read stuff into a CLLocationCoordinate2D to display it on a MKMapView.
So I have 2 problems :
1) How may I store the returned value given by the http request without loosing a digit, and keeping my function ?
2) If I acheiev to do so, how may I read the stuff and store it into a CLLocationCoordinate2D without loosing again a digit ?
You are not losing a digit of precision. When you use
If you do not specify a precision,
%fautomatically truncates your number to 6 decimal places as per the ANSI C standard.Try
This should return the same number as the return string.