What is the ideal data type to use when storing latitude / longitude in a MySQL database? What is the ideal data type to use when storing latitude / longitude in a MySQL database? mysql mysql

What is the ideal data type to use when storing latitude / longitude in a MySQL database?


Basically it depends on the precision you need for your locations. Using DOUBLE you'll have a 3.5nm precision. DECIMAL(8,6)/(9,6) goes down to 16cm. FLOAT is 1.7m...

This very interesting table has a more complete list: http://mysql.rjweb.org/doc.php/latlng :

Datatype               Bytes            ResolutionDeg*100 (SMALLINT)     4      1570 m    1.0 mi  CitiesDECIMAL(4,2)/(5,2)     5      1570 m    1.0 mi  CitiesSMALLINT scaled        4       682 m    0.4 mi  CitiesDeg*10000 (MEDIUMINT)  6        16 m     52 ft  Houses/BusinessesDECIMAL(6,4)/(7,4)     7        16 m     52 ft  Houses/BusinessesMEDIUMINT scaled       6       2.7 m    8.8 ftFLOAT                  8       1.7 m    5.6 ftDECIMAL(8,6)/(9,6)     9        16cm    1/2 ft  Friends in a mallDeg*10000000 (INT)     8        16mm    5/8 in  MarblesDOUBLE                16       3.5nm     ...    Fleas on a dog

Hope this helps.


Google provides a start to finish PHP/MySQL solution for an example "Store Locator" application with Google Maps. In this example, they store the lat/lng values as "Float" with a length of "10,6"

http://code.google.com/apis/maps/articles/phpsqlsearch.html