Populating geolocation field programmatically in drupal 8 is different from normal field values. This snippet does the trick:

$node = Node::create(
  'type' => 'location',
  'title' => 'My location',
  'geolocation_field' => ['lat'=> 41.264, 'lng' => 45.33]
);
$node->save();

 


Saved you some valuable time?

Donate and get more free time-saving code on this website in the future.