<p>I figured it out, didn't realise all I had to do was pass array like so:</p>

<pre><code>$entry-&gt;getContent()-&gt;address = array('lat' =&gt; $lat, 'lng' =&gt; $lng, 'street1' =&gt; $street1, 'zip' =&gt; $postcode);
</code></pre>

CC BY-SA 3.0
2016-06-17T20:47:48.507Z
+1 Perfect! Beat me to it, but your answer is spot on. :)
Lindsey D
CC BY-SA 3.0
2016-08-04T21:49:13.317Z
Super useful, thanks. Arrived here after having problems instantiating a `SmartMap_AddressModel`, setting its properties, then assigning it to the field name property of an `EntryModel` object.
August Miller
CC BY-SA 3.0
2016-06-17T07:18:07.810Z
2016-06-17T07:18:07.810Z
Dave Coggins
<p>I have a console command plugin that needs to periodically go and fetch property data via API and import it into Craft. I can pull in basic property information but when it comes to importing the data into Smart Map field I'm a bit lost as how to format the data so that it saves correctly. Has anyone had to do this before?</p>

<p>Edit:</p>

<p>I don't think the console command part should make much difference. Basically I am trying to save a smartmapfield on my entry. From the API I am using I get a string with the full address. I first extract the postcode and then use the smartmap plugin to get the Lat and Lng values:</p>

<pre><code>$postcode = $matches[0]; 

//Look up Latitude and Longitude from Google API

$response = craft()-&gt;smartMap-&gt;lookupCoords($postcode);
$lat = $response['lat'];
$lng = $response['lng'];
</code></pre>

<p>What I am not sure of is how to format this data so that it can be saved to the entry. So for standard fields thats straight forward:</p>

<pre><code>$entry-&gt;getContent()-&gt;title = $property['RoomName'];
</code></pre>

<p>How do I do this for my smartmap field?</p>

CC BY-SA 3.0
2016-06-16T18:36:08.837Z
Hi Dave. I haven't used the console command, but if you can show us what your code looks like so far, I may be able to help.
Lindsey D
CC BY-SA 3.0
2016-06-16T21:25:24.140Z
Hi Lindsey I have updated my question with more details, basically I'm trying to work out how to save an entry with smartmap field from within a plugin
Dave Coggins
<plugin-smartmap>
How to programmatically set a Smart Map address field in plugin
# How to programmatically set a Smart Map address field in plugin

(Asked by: username_0 on 2016-06-16)

I have a console command plugin that needs to periodically go and fetch property data via API and import it into Craft. I can pull in basic property information but when it comes to importing the data into Smart Map field I'm a bit lost as how to format the data so that it saves correctly. Has anyone had to do this before?
Edit:
I don't think the console command part should make much difference. Basically I am trying to save a smartmapfield on my entry. From the API I am using I get a string with the full address. I first extract the postcode and then use the smartmap plugin to get the Lat and Lng values:
$postcode = $matches[0]; 

//Look up Latitude and Longitude from Google API

$response = craft()->smartMap->lookupCoords($postcode);
$lat = $response['lat'];
$lng = $response['lng'];

What I am not sure of is how to format this data so that it can be saved to the entry. So for standard fields thats straight forward:
$entry->getContent()->title = $property['RoomName'];

How do I do this for my smartmap field?

**Tags:** plugin-smartmap
> **Comments:**
> **username_1**: Hi Dave. I haven't used the console command, but if you can show us what your code looks like so far, I may be able to help.  
> **username_0**: Hi Lindsey I have updated my question with more details, basically I'm trying to work out how to save an entry with smartmap field from within a plugin  

---

## 1 answers

### Answer by username_0 on 2016-06-17. Score: 5 | Accepted answer

I figured it out, didn't realise all I had to do was pass array like so:
$entry->getContent()->address = array('lat' => $lat, 'lng' => $lng, 'street1' => $street1, 'zip' => $postcode);

> **Comments:**
> **username_1**: +1 Perfect! Beat me to it, but your answer is spot on. :)  
> **username_2**: Super useful, thanks. Arrived here after having problems instantiating a `SmartMap_AddressModel`, setting its properties, then assigning it to the field name property of an `EntryModel` object.  

---

