How do I programmatically save longitute and latitude?
Try this :

$point = [
  'lat' =&gt; $lat,
  'lon' =&gt; $lon,
];
$value = \Drupal::service('geofield.wkt_generator')-&gt;WktBuildPoint($point);
$WayPointEntity-&gt;field_geo_field-&gt;setValue($value);