How to add longitude and latitude into cesium kmlDataSource without loading the file?

I am working with cesium workshop (code) (and I am new to cesium.js) and in order to view the kml file in cesium globe, we need to load the file by passing it with the file location:

var geocachePromise = Cesium.KmlDataSource.load('./Source/SampleData/sampleGeocacheLocations.kml', kmlOptions);

The entire code is available at (here)

My question: I have the longitude, and latitude, (and height) information saved in variables and instead of always saving them into .kml file and then load them via folder, I want to pass this information to cesium kmlDataSource directly.

Please let me know if you need more information about my question. Thanks

When you load a KML file in CesiumJS it automatically creates entities based on the data in the file.

If you already have the positions and/or geometry information, you can create your points/polygons directly with the Entity API, see for example this code example for creating polygons: https://sandcastle.cesium.com/?src=Polygon.html.

You may also find this guide helpful: https://cesium.com/docs/tutorials/creating-entities/