Oct 04, 2019 in Drupal 8, Snippets

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();