Invalid query: Data truncated for column 'lat' at row 1

274 views
Skip to first unread message

Daniel Montenegro

unread,
Nov 1, 2012, 9:05:12 AM11/1/12
to google-map...@googlegroups.com

I'm trying to implement a project very alike that:

https://developers.google.com/maps/articles/phpsqlinfo_v3

But I'm receiving this message from my phpsqlinfo_addrow.php:

Invalid query: Data truncated for column 'lat' at row 1

I don't know what's wrong because my lat lng columns were configured in the same way shown in the code. I checked the code a lot of times and there is no typo.

I'm using PHP 5 and MySQL Workbench.

Daniel

Jeff Lake

unread,
Nov 1, 2012, 9:27:21 AM11/1/12
to google-map...@googlegroups.com
That is telling you the data for the lat column your trying to insert
is to long, more then likely if your inserting directly from the form
there are to many decimal places

alter this code

$lat= $_GET['lat'];
$lng= $_GET['lng'];

to


$lat= $_GET['lat'];
$lat = round($lat,4);
$lng= $_GET['lng'];
$lon = round($lon,4);


-Jeff Lake
MichiganWxSystem.com
AllisonHouse.com
TheWeatherCenter.net
GRLevelXStuff.com
> --
> You received this message because you are subscribed to the Google
> Groups "Google Maps JavaScript API v3" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/google-maps-js-api-v3/-/-GXi7XlvcwYJ.
> To post to this group, send email to
> google-map...@googlegroups.com.
> To unsubscribe from this group, send email to
> google-maps-js-a...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/google-maps-js-api-v3?hl=en.

Jeff Lake

unread,
Nov 1, 2012, 9:37:08 AM11/1/12
to google-map...@googlegroups.com
whoops type-o


should be

$lat= $_GET['lat'];
$lat = round($lat,4);
$lng= $_GET['lng'];
$lng = round($lng,4);

-Jeff Lake
MichiganWxSystem.com
AllisonHouse.com
TheWeatherCenter.net
GRLevelXStuff.com

Daniel Montenegro

unread,
Nov 1, 2012, 6:39:26 PM11/1/12
to google-map...@googlegroups.com
This seems great but I round the numbers because I want the geographic coordinates of the markers...

Daniel

Daniel Montenegro

unread,
Nov 2, 2012, 8:34:24 AM11/2/12
to google-map...@googlegroups.com
Sorry, let me fix it:

This seems great but I CAN'T round the numbers because I want the geographic coordinates of the markers

Daniel

Barry Hunter

unread,
Nov 2, 2012, 9:05:18 AM11/2/12
to google-maps-js-api-v3
Round to 6 decimal places and you get about sub-1m accuracy. That is almost certainly better than the accuracy of the Google Maps themselves. 

The 'DECIMAL' column in the tutorial also uses 6 decimal places. You are getting the warning because Mysql is doing the truncation for you. Do it yourself before inserting and mysql wont issue the warning. 





--
You received this message because you are subscribed to the Google Groups "Google Maps JavaScript API v3" group.

Daniel Montenegro

unread,
Nov 2, 2012, 1:45:03 PM11/2/12
to google-map...@googlegroups.com
Thanks Jeff and Barry,

Actually I've changed the column type to VARCHAR and now mysql is working fine.

Do you believe this is ok?

Daniel


Barry Hunter

unread,
Nov 2, 2012, 2:00:26 PM11/2/12
to google-maps-js-api-v3
On Fri, Nov 2, 2012 at 5:45 PM, Daniel Montenegro <dmonte...@gmail.com> wrote:
Thanks Jeff and Barry,

Actually I've changed the column type to VARCHAR and now mysql is working fine.

lol. You are lucky mysql is so forgiving. 

 

Do you believe this is ok?

Its 'ok' in that it appears to work. But its really bad practice in general. 

As a varchar, indexes on the column wont work well. Because mysql is not storing a string, every time you want to use the column as a number (eg <, > or between etc) mysql will have to convert to a number. 
The difference will be not noticeable if you only have a few rows in your table. Put a few thousend rows and you will notice. 


I would recommend using a proper numeric column. Using a varchar is just brushing the issue under the carpet. It will come back and bite you later. 


Storing more than 6 decimal places is pointless, you are deluding yourself if you think storing more is worth it. If you really want to to store more use a float or a double column type. Either would be miles better than a varchar. 

 

Barry Hunter

unread,
Nov 2, 2012, 2:20:24 PM11/2/12
to google-maps-js-api-v3

Jeff Lake

unread,
Nov 2, 2012, 2:43:31 PM11/2/12
to google-map...@googlegroups.com
Agreed with Barry ...
anything over 4 decimals is over kill,

-Jeff Lake
MichiganWxSystem.com
AllisonHouse.com
TheWeatherCenter.net
GRLevelXStuff.com
--
You received this message because you are subscribed to the Google Groups "Google Maps JavaScript API v3" group.

Daniel Montenegro

unread,
Nov 2, 2012, 7:58:58 PM11/2/12
to google-map...@googlegroups.com
Do you know why mysql does not allow me to turn lat lng columns into FLOAT again?
I have changed the code as Jeff sugested but now I can't change the column datatype ...
To unsubscribe from this group, send email to google-maps-js-api-v3+unsub...@googlegroups.com.

Barry Hunter

unread,
Nov 2, 2012, 8:15:58 PM11/2/12
to google-maps-js-api-v3
On Fri, Nov 2, 2012 at 11:58 PM, Daniel Montenegro <dmonte...@gmail.com> wrote:
Do you know why mysql does not allow me to turn lat lng columns into FLOAT again?

Nope. Did you get an error message?
 
I have changed the code as Jeff sugested but now I can't change the column datatype ...


 If you changed the code as suggested you dont need to use FLOAT. Could stick with the DECIMAL(10,6) suggested in the article. 

Daniel Montenegro

unread,
Nov 2, 2012, 8:53:38 PM11/2/12
to google-map...@googlegroups.com
The message error is:

ERROR 1366: Incorrect decimal value: '' for column '' at row -1
Reply all
Reply to author
Forward
0 new messages