Set geolocation field programmatically in drupal 8 [solved]

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?

Buy me a drink 🍺 to keep me motivated to create free content like this!