Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Datatype to Store Longitude/Latitude in Mysql

'43.005895','-71.013202'

Trying to use:

INSERT INTO table(fanDetLocZip, fanDetLocCity, fanDetLocState, fanDetLocLat, fanDetLocLong, fanDetLocTZ, fanDetLocDST)  
VALUES(00210, 'Portsmouth', 'NH', '43.005895', '-71.013202', -5, 1);

I'm currently using the datatype SPATIAL, GEOMETRY.

Its giving me errors like:

Cannot get geometry object from data you send to the GEOMETRY field

All the values have 2 digits, and 6 decimal places after decimal. How do I store this in mysql?

Error I get when I use:
INSERT INTO Table(fanDetLocZip, fanDetLocCity, fanDetLocState, fanDetLocLatLong, fanDetLocTZ, fanDetLocDST)
VALUES(00210, 'Portsmouth', 'NH', point(43.005895,-71.013202), -5,1)

Error Image:img5

like image 554
CodeTalk Avatar asked Mar 05 '12 00:03

CodeTalk


People also ask

Which datatype is used for latitude and longitude?

Latitude and Longitude should use DECIMAL datatype instead of FLOAT #4923.

What is the data type for GPS?

The latitude/longitude coordinates generated by the GPS are considered the standard for location data. Your device receives signals from the satellites and it can calculate where it is by measuring the time it takes for the signal to arrive.

How many bytes can you store latitude and longitude?

latitude : 4-Byte Floating Point Number Specifies the geographic latitude of the location. longitude : 4-Byte Floating Point Number Specifies the geographic longitude of the location.

What are types of longitude?

The prime meridian defines 0° longitude; by convention the International Reference Meridian for the Earth passes near the Royal Observatory in Greenwich, England on the island of Great Britain. Positive longitudes are east of the prime meridian, and negative ones are west.


2 Answers

You can use POINT() to store into a column of type GEOMETRY or POINT:

POINT(43.005895, -71.013202)

If the Geometry column is named geom, you can use this:

INSERT INTO table
    ( ..., geom, ...) 
  VALUES
    ( ..., POINT(43.005895, -71.013202), ...)

If you want to show data stored, you can use the X() and Y() functions:

SELECT X(geom) AS x, Y(geom) AS y
FROM table 
like image 55
ypercubeᵀᴹ Avatar answered Oct 05 '22 11:10

ypercubeᵀᴹ


Why dont you use instead a Float type for your lat/long?

Float (10,6)
like image 44
Kevin Fauver Avatar answered Oct 05 '22 12:10

Kevin Fauver