在Mysql中存储经度/纬度的数据类型

时间:2020-12-25 16:56:44
'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.

我目前正在使用数据类型SPATIAL,GEOMETRY。

Its giving me errors like:

它给我的错误如下:

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

无法从发送到GEOMETRY字段的数据中获取几何对象

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

所有值都有2位数,小数点后6位小数。我如何将其存储在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)

我在使用时遇到错误:INSERT INTO表(fanDetLocZip,fanDetLocCity,fanDetLocState,fanDetLocLatLong,fanDetLocTZ,fanDetLocDST)VALUES(00210,'朴茨茅斯','NH',点(43.005895,-71.013202), - 5,1)

Error Image:在Mysql中存储经度/纬度的数据类型

错误图片:

2 个解决方案

#1


18  

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

您可以使用POINT()存储到GEOMETRY或POINT类型的列中:

POINT(43.005895, -71.013202)

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

如果Geometry列名为geom,则可以使用:

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:

如果要显示存储的数据,可以使用X()和Y()函数:

SELECT X(geom) AS x, Y(geom) AS y
FROM table 

#2


2  

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

你为什么不用lat / long来代替Float类型?

Float (10,6)

#1


18  

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

您可以使用POINT()存储到GEOMETRY或POINT类型的列中:

POINT(43.005895, -71.013202)

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

如果Geometry列名为geom,则可以使用:

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:

如果要显示存储的数据,可以使用X()和Y()函数:

SELECT X(geom) AS x, Y(geom) AS y
FROM table 

#2


2  

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

你为什么不用lat / long来代替Float类型?

Float (10,6)