<p>I fiddled around with some fields and got this working. Not sure it's the most direct way, but hey. Progress is progress :)</p>

<pre><code>{% set locations = craft.entries.section('locations').limit(null) %}

{# Look for each campus listed #}
{% for entry in craft.entries.section('campuses').limit(null) %}
    {% if entry.campusAddress|length %}
        {% set options = {
            markerOptions: {
                address: entry.campusAddress
            }
        } %}
    {% endif %}
{% endfor %}
</code></pre>

CC BY-SA 3.0
2016-08-10T13:46:36.327Z
2016-08-10T13:46:36.327Z
Josh Kennedy
<p>Author of Smart Map here...</p>

<p>It sounds like your locations <em>are</em> in a section (a Structure is a type of section). The first line of your solution is exactly what you'd need to get the <code>locations</code> value.</p>

<pre><code>{% set locations = craft.entries.section('locations').limit(null) %}

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

<p>Just to clarify...</p>

<ul>
<li>Are you using the "Address (Smart Map)" field to store your addresses?</li>
<li>And do each of those addresses contain "Latitude" and "Longitude" values?</li>
</ul>

<p>If so, the code example above should definitely work for you!</p>

CC BY-SA 3.0
2016-08-12T01:29:46.027Z
Hey @Lindsey you're absolutely right, I misspoke about my locations being in a section - I mean't to say that my locations themselves were not a section, but contained within entries within a section. I think I wasn't sure how Craft or Smart Map was going to dive into each entry within said section to grab the Address (Smart Map) field values, since the locations have many different fields within them.

You're correct, the code accomplishes just what I needed, and Smart Map has been great to work with thus far, now that I've switched context from the former plugin. Great work and thanks!
Josh Kennedy
CC BY-SA 3.0
2016-08-12T03:09:07.140Z
Awesome, thanks Josh! Glad you're digging the plugin. If you need any help in the future, feel free to email me at support@doublesecretagency.com :)
Lindsey D
CC BY-SA 3.0
2016-08-10T22:09:58.520Z
2016-08-10T22:09:58.520Z
Lindsey D
<p>I feel like I'm overlooking something simple here, but I can't for the life of me figure out how to add markers to a map. I had this working with the <a href="https://github.com/objectivehtml/Google-Maps-for-Craft" rel="nofollow noreferrer">Google Maps for Craft</a> plugin but since switching to Smart Map I get as far as rendering a map and that's it.</p>
<p>My set up is such: I have a structure with multiple same-level entries, each of which has an address. I have an index page that's rendering a map which should be populated with markers based on the the addresses from each entry's address field.</p>
<p>Historically, I looped through the entries, defined each marker's address and then added that to the map variable like so:</p>
<pre><code>{# Look for each location listed #}
{% for entry in craft.entries.section('locations').limit(null) %}
    {# For each location found, set the map marker properties to have an 
       address and a link to the location page within the pop-out menu that 
       shows on-click #}
    {% set marker = {
        address: entry.locationAddress,
        content: '...'
    } %}
    {# Then we add the marker to our map variable #}
    {{ craft.googleMaps.marker('map', marker) }}
{% endfor %}
</code></pre>
<p>However, now with Smart Map, I can't figure out how to recreate this. I don't quite understand how to set the <code>locations</code> for the <code>{{ craft.smartMap.map(locations, options) }}</code> call. The docs show that one can pass an array into it via <code>craft.entries.section('myLocations')</code> but since my address fields are not entries in a section I'm not sure how to parse that out.</p>
<p>Any help or insight would be greatly appreciated, thanks!</p>

<plugin-smartmap>
Adding markers to map from field in entries within section
# Adding markers to map from field in entries within section

(Asked by: username_0 on 2016-08-10)

I feel like I'm overlooking something simple here, but I can't for the life of me figure out how to add markers to a map. I had this working with the Google Maps for Craft plugin but since switching to Smart Map I get as far as rendering a map and that's it.
My set up is such: I have a structure with multiple same-level entries, each of which has an address. I have an index page that's rendering a map which should be populated with markers based on the the addresses from each entry's address field.
Historically, I looped through the entries, defined each marker's address and then added that to the map variable like so:
{# Look for each location listed #}
{% for entry in craft.entries.section('locations').limit(null) %}
    {# For each location found, set the map marker properties to have an 
       address and a link to the location page within the pop-out menu that 
       shows on-click #}
    {% set marker = {
        address: entry.locationAddress,
        content: '...'
    } %}
    {# Then we add the marker to our map variable #}
    {{ craft.googleMaps.marker('map', marker) }}
{% endfor %}

However, now with Smart Map, I can't figure out how to recreate this. I don't quite understand how to set the locations for the {{ craft.smartMap.map(locations, options) }} call. The docs show that one can pass an array into it via craft.entries.section('myLocations') but since my address fields are not entries in a section I'm not sure how to parse that out.
Any help or insight would be greatly appreciated, thanks!

**Tags:** plugin-smartmap


---

## 2 answers

### Answer by username_1 on 2016-08-10. Score: 4 | Accepted answer

Author of Smart Map here...
It sounds like your locations are in a section (a Structure is a type of section). The first line of your solution is exactly what you'd need to get the locations value.
{% set locations = craft.entries.section('locations').limit(null) %}

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

Just to clarify...

Are you using the "Address (Smart Map)" field to store your addresses?
And do each of those addresses contain "Latitude" and "Longitude" values?

If so, the code example above should definitely work for you!

> **Comments:**
> **username_0**: Hey @Lindsey you're absolutely right, I misspoke about my locations being in a section - I mean't to say that my locations themselves were not a section, but contained within entries within a section. I think I wasn't sure how Craft or Smart Map was going to dive into each entry within said section to grab the Address (Smart Map) field values, since the locations have many different fields within them.  You're correct, the code accomplishes just what I needed, and Smart Map has been great to work with thus far, now that I've switched context from the former plugin. Great work and thanks!  
> **username_1**: Awesome, thanks Josh! Glad you're digging the plugin. If you need any help in the future, feel free to email me at support@doublesecretagency.com :)  

---

### Answer by username_0 on 2016-08-10. Score: 2

I fiddled around with some fields and got this working. Not sure it's the most direct way, but hey. Progress is progress :)
{% set locations = craft.entries.section('locations').limit(null) %}

{# Look for each campus listed #}
{% for entry in craft.entries.section('campuses').limit(null) %}
    {% if entry.campusAddress|length %}
        {% set options = {
            markerOptions: {
                address: entry.campusAddress
            }
        } %}
    {% endif %}
{% endfor %}


---

