Hi there guys I need help with handling location co-ordinates with xcode开发者_运维百科; to be precise, the conversions. i have CLLocation object, which has lat and long received using the phone's geo location, works fine. But i am having issues handling the conversions.
i am storing the lat and long values in the userdefaults using
[defaults setObject:[NSString stringWithFormat:@"%.9lf",location.coordinate.latitude] forKey:@"lastKnownLat"];
but the decimal values of the location is ofcourse not precise, its could be 3.123456789 or 3.12345 - in the later case, the value is converted to 3.123459999 which i presume gives wrong positioning on the map.
How can i avoid this? What could be the best way to store lat/long values and show them on the map? in the mapkit, will it maek a lot of difference between 3.12345 and 3.12345999?
Thanks
NSUserDefaults
has methods specifically for saving floating-point values, and you can use setDouble:forKey: to preserve as much precision as possible.
The best way to store the data itself could be through Core Data or sqlite, but to have the most accurate data you want to use kCLLocationAccuracyBest. See below (refreshLoc is my CLLocationManager variable).
refreshLoc = [[CLLocationManager alloc] init];
refreshLoc.delegate = self;
refreshLoc.desiredAccuracy = kCLLocationAccuracyBest;
refreshLoc.distanceFilter = kCLDistanceFilterNone;
[refreshLoc startUpdatingLocation];
精彩评论