How do I programmatically save longitute and latitude? I am using the Geofield Map module which depends on the geofield and I want to save lng and lat pragmatically in the geofield via my controller. I have tried the methods below and they didn't work:

$WayPointEntity-&gt;field_geo_field-&gt;setValue("POINT(" .$waypoint['lng']." " .$waypoint['lat'].")");


I also tried:

$WayPointEntity-&gt;field_geo_field = array(
                  'input_format' =&gt; GEOFIELD_INPUT_LAT_LON,
                  'geom' =&gt; array('lat' =&gt; $waypoint['lat'], 'lon' =&gt; $waypoint['lng']),
              );


  $WayPointEntity-&gt;save();
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);