sqldatabasegeocodinglatitude-longitude

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


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.


Solution

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

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

    Latitude and Longitude ##.###### and ###.######

    To 6 decimal places should get you to around ~10cm of accuracy on a coordinate.