The OP also defines $data in the $entity as a string where the documentation specifies it should be a number.
In reply to Re^2: Creating a kml file by Lotus1 in thread Creating a kml file by RFMonk