I am writing a module to import some data from an external source. I want to import latitude and longitude data directly into the location module. How do I achieve this for the node object?

For other fields I use $node->body = '.....';

Any hints much appreciated.

Comments

yesct’s picture

Issue tags: +location importing

I think you might have to set the number of locations on a node to 1 (or more)
then try something like node->location[0]['latitude']= ...
then something like node_save(...)

?

Post back any thoughts on that, or partial code you try. That will help more people give you more feedback.

also tagging.

ps. I found it helpful to use the devel and/or the contemplate module to find out how to access the parts of location.

ankur’s picture

Status: Active » Closed (fixed)

$node->locations is an array of locations where each array can have values for a 'latitude' key and a 'longitude' key. Building your stdClass node object with this locations attribute and then calling location_save() with this object (as suggested by YesCT above) should do it.