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.

Lindsey D
  • 23,974
  • 5
  • 53
  • 110
  • 1
    Turns out this code works fine. Adjusting zoom level showed proper results. Ahem! – Micky Kelleher Dec 20 '16 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 Dec 20 '16 at 22:36

1 Answers1

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) }}
Lindsey D
  • 23,974
  • 5
  • 53
  • 110
carlcs
  • 36,220
  • 5
  • 62
  • 139