What datatype to use when storing latitude and longitude data in SQL databases?

dthrasher picture dthrasher · Jul 28, 2009 · Viewed 237.1k times · Source

When storing latitude or longitude data in an ANSI SQL compliant database, what datatype would be most appropriate? Should float be used, or decimal, or ...?

I'm aware that Oracle, MySql, and SQL Server have added some special datatypes specifically for handling geo data, but I'm interested in how you would store the information in a "plain vanilla" SQL database.

Answer

dotjoe picture dotjoe · Jul 28, 2009

For longitudes use: Decimal(9,6), and latitudes use: Decimal(8,6)

If you're not used to precision and scale parameters, here's a format string visual:

###.###### and ##.######