Search code examples
sql-server-2005geolocationgeotagging

Storing geo data


Hi I'm using ms sql 2005 to store some latlng data. It is currently being stored in a nvarchar column in the following form - "35.6949965,139.7555035" My questions are. Is this the best way to store this kind of data? If I do store the latlng in this way is it going to come and bite me later, or will it mean just that I will have to do any processing outside of the database?

Any pointers appreciated,


Solution

  • It's almost certainly not the best way to store it. If you use a pair of floating-point columns - latitude and longitude - then you can perform some functions within the database itself. As an example, here's how to calculate the distance between two points:

    http://www.zipcodeworld.com/samples/distance.mssql.html

    Or, as a trivial example,

    SELECT * FROM table WHERE latitide<40;
    

    would find everywhere north of New York.