4

I have a Smart Map field in a section and am trying to output multiple results (pins) to a single map.

This code will output multiple maps (one map per pin)

{% for mapEntry in craft.entries.section('markets') %}
{% set options = {
    height: 500,
    zoom: 14,
    draggable: false,
    markerInfo: '_includes/mapInfoBubble',
    markerOptions: {
        icon: 'http://maps.google.com/mapfiles/ms/icons/green-dot.png'
    },
    infoWindowOptions: {
        maxWidth: 200
    }
} %}

{% set locations = craft.entries.section('markets').marketAddress.find() %}

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

{% endfor %}

So essentially I am trying to get the {{ craft.smartMap.map(locations, options) }} outside the for loop.

{% set locations = '' %}
{% set options = '' %}
{% for mapEntry in craft.entries.section('markets') %}
{% set options = {
    height: 500,
    zoom: 14,
    draggable: false,
    markerInfo: '_includes/mapInfoBubble',
    markerOptions: {
        icon: 'http://maps.google.com/mapfiles/ms/icons/green-dot.png'
    },
    infoWindowOptions: {
        maxWidth: 200
    }
} %}
{% set locations = craft.entries.section('markets').marketAddress.find() %}
{{ craft.smartMap.map(locations, options) }}
{% endfor %}

But this only results in a single pin (most recent entry).

Can't get my head around this. Any assistance most welcome.

2
  • 1
    Turns out this code works fine. Adjusting zoom level showed proper results. Ahem! Commented Dec 20, 2016 at 17:50
  • Glad you got it worked out! For any other folks just passing by, a zoom level of 14 is extremely close. The maximum is 16, which practically shows your front doorstep. (Conversely, 1 is a distant view from outer space.)
    – Lindsey D
    Commented Dec 20, 2016 at 22:36

1 Answer 1

3

According to the docs, locations has to be an array of elements or an ElementCriteriaModel if you want to display multiple markers.

{% set mapEntries = craft.entries.section('markets') %}
{{ craft.smartMap.map(mapEntries, options) }}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.