Can I store WGS84 latitude / longitude directly as spatial data in MySQL?

3.6k Views Asked by At

I have a set of WGS84 coordinates. The conservative approach is to store them as number ( What datatype to use when storing latitude and longitude data in SQL databases? ) and calculate distances as here ( latitude/longitude find nearest latitude/longitude - complex sql or complex calculation).

A little more advanced approach is to create a user defined function for "in range" ( MySQL User Defined Function for Latitude Longitude Syntax )

MySQL latitude and Longitude table setup uses a spatial index . But I do not quite get if it is possible to directly store WGS coordinates, and then query a distance based on the Point data type?

Example: Data look like this: "lat" 40.7142298, "lng" -73.9614669, and this is what I'd like to import. Then query like "select all tupel within 10km of lat / lng".

2

There are 2 best solutions below

3
On BEST ANSWER

Have you read the Manual section on the Spatial Extensions?

To query, define a query region (e.g. rectangle) and then filter by within

1
On

SQL server 2008 has Geography data type you can use and to query it back use open query. once that is done, geo spatial your database and start doing stuff.