<p>At a glance, your code <em>looks</em> perfect... but I think there's a subtle error. The <code>locations</code> parameter can be an array of <strong>elements</strong>, but you are building an array of <strong>Address fields</strong> (which is not valid).</p>
<blockquote>
<p><a href="https://plugins.doublesecretagency.com/smart-map/render-a-map-in-twig/" rel="nofollow noreferrer">https://plugins.doublesecretagency.com/smart-map/render-a-map-in-twig/</a></p>
</blockquote>
<p><a href="https://i.sstatic.net/GFUYT.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/GFUYT.png" alt="locations" /></a></p>
<p>You can simplify the middle part of your code to this:</p>
<pre><code>{# add entry to locations array #}
{% set locations = locations|merge([member]) %}
</code></pre>
<p>That way, <code>locations</code> will end up being <strong>an array of elements</strong>.</p>

CC BY-SA 3.0
2017-08-30T19:08:31.090Z
That did it. Makes sense. I think in my head, doing it that way didn't seem specific enough.
artmem
CC BY-SA 3.0
2017-09-08T16:56:35.320Z
Is it possible to get reverse relationship data back out of my locations array? Each matrix block has a field for venueType, in addition to my relationship field. I'd like to be able to get the venueType data for each location to create custom icons. {% set venues = craft.entries.section('members','events').relatedTo({
    targetElement: entry,
    field: 'myMatrix.matrixRelationshipField'
}) %} doesn't work.
artmem
CC BY-SA 3.0
2017-09-08T17:13:09.003Z
Figured it out:     {% set venue = entry.featuredMembers.myMatrix.relatedTo(location).first() %} 
    {{ venue.venueType }}
artmem
CC BY-SA 3.0
2017-09-08T17:15:50.217Z
@artmem That sounds like a completely unrelated question, and should probably be asked as a new thread (for future reference).
Lindsey D
CC BY-SA 4.0
2017-08-30T17:45:09.543Z
2021-01-01T06:53:51.163Z
2021-01-01T06:53:51.163Z
Lindsey D
<p>I have "locations" section where each entry is a location, with a Smart Map field for the address.</p>

<p>I have another section "pages", where I have a matrix field which contains an entry relationship field, where I can select entries (locations) from the first channel.</p>

<p>I'm trying to output a map of all locations selected in my matrix field, but I'm getting an error:
Property "Craft\SmartMap_AddressModel.title" is not defined.</p>

<p>I'm using the code below to get the address fields from the individual entries, and put them into an array. I think maybe I'm not understanding what exactly needs to be in the locations array:</p>

<pre><code>{% set locations = [] %}

{#  loop though all relationship fields for this entry #}
{% for block in entry.pageBuilder.type('listingGroup') %}

    {#  loop through related entries #}
    {% for member in block.listing %}

        {# get individual entry address #}
        {% set address = member.address %}

        {# add entry address to locations array #}
        {% set locations = locations|merge([address])%}

    {% endfor %}
{% endfor %}

{{ craft.smartMap.map(locations, options) }}
</code></pre>

<matrix><relations><plugin-smartmap>
Smart Map - Output map locations from relationship file in a matrix
# Smart Map - Output map locations from relationship file in a matrix

(Asked by: username_0 on 2017-08-30)

I have "locations" section where each entry is a location, with a Smart Map field for the address.
I have another section "pages", where I have a matrix field which contains an entry relationship field, where I can select entries (locations) from the first channel.
I'm trying to output a map of all locations selected in my matrix field, but I'm getting an error:
Property "Craft\SmartMap_AddressModel.title" is not defined.
I'm using the code below to get the address fields from the individual entries, and put them into an array. I think maybe I'm not understanding what exactly needs to be in the locations array:
{% set locations = [] %}

{#  loop though all relationship fields for this entry #}
{% for block in entry.pageBuilder.type('listingGroup') %}

    {#  loop through related entries #}
    {% for member in block.listing %}

        {# get individual entry address #}
        {% set address = member.address %}

        {# add entry address to locations array #}
        {% set locations = locations|merge([address])%}

    {% endfor %}
{% endfor %}

{{ craft.smartMap.map(locations, options) }}

**Tags:** matrix, relations, plugin-smartmap

---

## 1 answers

### Answer by username_1 on 2017-08-30. Score: 2 | Accepted answer

At a glance, your code looks perfect... but I think there's a subtle error. The locations parameter can be an array of elements, but you are building an array of Address fields (which is not valid).

https://plugins.doublesecretagency.com/smart-map/render-a-map-in-twig/


You can simplify the middle part of your code to this:
{# add entry to locations array #}
{% set locations = locations|merge([member]) %}

That way, locations will end up being an array of elements.

> **Comments:**
> **username_0**: That did it. Makes sense. I think in my head, doing it that way didn't seem specific enough.  
> **username_0**: Is it possible to get reverse relationship data back out of my locations array? Each matrix block has a field for venueType, in addition to my relationship field. I'd like to be able to get the venueType data for each location to create custom icons. {% set venues = craft.entries.section('members','events').relatedTo({     targetElement: entry,     field: 'myMatrix.matrixRelationshipField' }) %} doesn't work.  
> **username_0**: Figured it out:     {% set venue = entry.featuredMembers.myMatrix.relatedTo(location).first() %}      {{ venue.venueType }}  
> **username_1**: @artmem That sounds like a completely unrelated question, and should probably be asked as a new thread (for future reference).  

---

