Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the best way to store co-ordinates (longitude/latitude, from Google Maps) in SQL Server?

I'm designing a table in SQL Server 2008 that will store a list of users and a Google Maps co-ordinate (longitude & latitude).

Will I need two fields, or can it be done with 1?

What's the best (or most common) data-type to use for storing this kind of data?

like image 787
Jonathan Avatar asked Feb 16 '09 00:02

Jonathan


People also ask

How do you store latitude and longitude in a database?

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).

Is there a better SQL type for latitude and longitude than double?

To summarise: The most precise available option is DOUBLE . The most common seen type used is DECIMAL(8,6)/(9,6) .

What data type should I use for latitude and longitude?

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) .


1 Answers

Fair Warning! Before taking the advice to use the GEOGRAPHY type, make sure you are not planning on using Linq or Entity Framework to access the data because it's not supported (as of November 2010) and you will be sad!

Update Jul 2017

For those reading this answer now, it is obsolete as it refers to backdated technology stack. See comments for more details.

like image 116
dan90266 Avatar answered Oct 23 '22 21:10

dan90266