I have done research on Google and read some answers on Stack Overflow. DECIMAL
is a good choice for storing latitude and longitude data.
But people have different opinions about the numbers of digit before and after the decimal point.
Latitude range can be max 2 digits (-90 and 90) and longitude range can be max 3 digits (-180 and 180).
The numbers of digit after the decimal point that I get from a Restful API is 12 digits.
Thus the database columns can be as following.
lat DECIMAL(14, 12)
lon DECIMAL(15, 12)
I feel safe to set more max digits as following, in case numbers of digit increase.
lat DECIMAL(17, 13)
lon DECIMAL(17, 13)
This way, both lat
and lon
can store data up to xxxx.xxxxxxxxxxxxx
, thus 4 digits
before the decimal point and 13 digits
after the decimal point. Does it have import on the performance in MySQL and it is not necessary? I feel stupid to set them so because lat range is -90 and 90
and lon range is -180 and 180
, but I feel more safe. But at the same time I concern about the performance.
Or just set them to:
lat DECIMAL(14, 12)
lon DECIMAL(15, 12)
And no need to worry about anything because this is already completely safe for storing latitude and longitude data?