I am building a geolocation based app and i want to know which data type is best for storing lat/long i am using doubleValue but i think we can be more precise like 10 decimal places .
precision you should use DECIMAL . Latitudes range from -90 to +90 (degrees), so DECIMAL(10,8) is ok for that, but longitudes range from -180 to +180 (degrees) so you need DECIMAL(11,8) .
The most precise available option is DOUBLE . The most common seen type used is DECIMAL(8,6)/(9,6) .
Storing Latitude & Longitude data as Floats or Decimal This is one of the most fundamental ways of storing geocoordinate data. Latitude & longitude values can be represented & stored in a SQL database using decimal points (Decimal degrees) rather than degrees (or Degrees Minutes Seconds).
Most GPS devices provide coordinates in the Degrees, Minutes and Seconds (DMS) format, or most commonly the Decimal Degrees (DD) format. The popular Google Maps provides their coordinates in both DMS and DD formats.
double
is the value used by the iOS itself. iOS uses CLLocationDegrees
to represent lat/long values which is a typedef of double.
IMO, using double
/CLLocationDegrees
would be the best choice.
Looking at the definition of CLLocationCoordinate2D:
typedef struct {
CLLocationDegrees latitude;
CLLocationDegrees longitude;
}
CLLocationCoordinate2D;
and then the location of CLLocationDegrees;
typedef double CLLocationDegrees;
we can see that the precision is given as double. Thus, you can't make it better than that.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With