Programmatically save coordinates I have read in a lot of sources that I should use the geofield_compute_values() when trying to programmatically save coordinates in Drupal, but it does not work for me. That function doesn't exist in Drupal 8.5.2.

I've installed the Geofield module using Composer and I can use it as usual in the admin area. There are no problems with saving.

This is the code I tried, which returns an error about a not existing function (geofield_compute_values()).

$geofield_data = geofield_compute_values(['lat' =&gt; $lat, 'lon' =&gt; $lon    ], GEOFIELD_INPUT_LAT_LON);
$cbisProduct-&gt;set('field_koordinater', $geofield_data);


I have also tried this out with no successful result and no errors.

$geofield = [
  'geom' =&gt; "POINT (" . $lon . " " . $lat . ")",
  'geo_type' =&gt; 'point',
  'lat' =&gt; $lat,
  'lon' =&gt; $lon,
  'left' =&gt; $lon,
  'top' =&gt; $lat,
  'right' =&gt; $lon,
  'bottom' =&gt; $lat,
];
$cbisProduct-&gt;set('field_koordinater', $geofield);


I also tried the solution given in How to save LNG and LAT progamatically in a geofield, but it didn't work either. 

How can I programmatically save coordinates?
Try this:

$entity-&gt;set('field_geofield_name', [sprintf("'POINT (%s %s)'", $longitude, $latitude)]);


Cheers!