Storing coordinate from Core Location in Core Data. Float or Double?
A 32-bit float holds 7 digits of precision, a 64-bit double holds 15 digits of precision.
With 7 digits of precision the maximum longitude of 179.9999 is only accurate down to 0.0001 degrees. A degree is about 60 nautical miles so 0.0001 degrees is about 10 meters (33 feet). If you want to store more precise lat/lon values, then you need to use a double (or a fixed point integer).
These days it doesn't matter much.
A double is just a float value slot that can hold twice as much precision as a standard float. Unless you force it to use a float, the Objective-c compiler will actually store all float values as a double.
Floats and Doubles are largely hold overs from the old days when memory was super tight. These days, you usually only see them different when it comes to string formatting. It's the same with various sizes of int. All sizes are stored in the largest available size unless you force the compiler to do otherwise.
For answering which accuracy you have when using floats or double I have come up with this answer:
Worst case accuracy when storing as decimal numbers for E/W and N/S:
- float: 1.6955566 meters
- double: 3.1582203519064933E-9 meters. (That is 3 nm)
You can do the calculations yourself by running this in Java:
public class Main {
public static void main(String[] args) {
System.out.println(Math.ulp((float) 180) * 60 * 1852);
System.out.println(Math.ulp((double) 180) * 60 * 1852);
}
}
I know this is an old thread but I found it while searching for the problem. Float is most probably enough for most applications. The GPS of the Apple device in question does probably not have better accuracy than that. But it is easier to store doubles as long as data is not a concern.