Answers.Body: <p>I believe the problem is in this line of code:</p>
  
  <pre><code>var markerId = 'smartmap-mapcanvas-1.{{ entry.id }}.address';
  </code></pre>
  
  <p>Because you're generating markers from <strong>matrix blocks</strong>, you'll need to use the <em>block</em> ID instead of the entry ID. In your case, that may looks something like this:</p>
  
  <pre><code>var markerId = 'smartmap-mapcanvas-1.{{ item.id }}.address';
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-01-04T21:32:24.860Z
Answers.Text: This was indeed the source of my problem, thank you very much!
Answers.UserDisplayName: BryanB
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-01-04T21:10:38.887Z
Answers.LastActivityDate: 2016-01-04T21:10:38.887Z
Answers.UserDisplayName: Lindsey D
Body: <p>I'm having some trouble setting different markers using the smart map plugin and was hoping someone might be able to point me in a direction I might not see.</p>
  <p>The different locations are are set through a matrix field with two different block types; one that should return a blue marker and one that should return a green. I've been following the docs at: <a href="https://plugins.doublesecretagency.com/smart-map/different-icons-for-different-marker-types/" rel="nofollow noreferrer">https://plugins.doublesecretagency.com/smart-map/different-icons-for-different-marker-types/</a> but have still been getting a javascript error preventing it to be rendered.</p>
  <p>The javascript error is &quot;uncaught TypeError: Cannot read property 'setOptions' of undefined. I'm sure this is because the markerId variable isn't getting the address from the matrix field.</p>
  <p>Any help or insight would be greatly appreciated, thanks!</p>
  <pre><code> {% set locations = entry.filmMap %}
  {% set mapOptions = {
      height: 580,
      zoom: 10,
      draggable: true,
      markerInfo: '_includes/mapInfoBubble',
      markerOptions: {
      icon: 'http://maps.google.com/mapfiles/ms/icons/green-dot.png'
    }
  } %}
  
  {{ craft.smartMap.map(locations, mapOptions) }}
  
  {# Loop through location entries #}
  {% for item in locations %}
  
    {% switch item.type %}
      {% case 'filmSites' %}
        {% set icon = '/assets/src/images/blue-marker.png' %}
      {% case 'castingCalls' %}
        {% set icon = '/assets/src/images/green-marker.png' %}
      {% default %}
        {% set icon = 'http://maps.google.com/mapfiles/ms/icons/green-dot.png' %}
    {% endswitch %}
  
    {% set address = item.address %}
  
    {# JS: Change marker icon #}
    {% includejs %}
  
      var markerId = 'smartmap-mapcanvas-1.{{ entry.id }}.address';
      smartMap.marker[markerId].setOptions({'icon': '{{ icon }}'});
  
    {% endincludejs %}
  
  {% endfor %}
  </code></pre>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-01-04T21:05:59.160Z
Comments.Text: I'm impressed... I only added that page to the documentation 2 days ago. ;)
Comments.UserDisplayName: Lindsey D
Tags: <plugin-smartmap>
Title: Smart Map with multiple different markers based on a matrix field
ThreadText: # Smart Map with multiple different markers based on a matrix field
  
  (Asked by: username_0 on 2016-01-04)
  
  I'm having some trouble setting different markers using the smart map plugin and was hoping someone might be able to point me in a direction I might not see.
  
  The different locations are are set through a matrix field with two different block types; one that should return a blue marker and one that should return a green. I've been following the docs at: <https://plugins.doublesecretagency.com/smart-map/different-icons-for-different-marker-types/> but have still been getting a javascript error preventing it to be rendered.
  
  The javascript error is "uncaught TypeError: Cannot read property 'setOptions' of undefined. I'm sure this is because the markerId variable isn't getting the address from the matrix field.
  
  Any help or insight would be greatly appreciated, thanks!
  
  ```
   {% set locations = entry.filmMap %}
  {% set mapOptions = {
      height: 580,
      zoom: 10,
      draggable: true,
      markerInfo: '_includes/mapInfoBubble',
      markerOptions: {
      icon: 'http://maps.google.com/mapfiles/ms/icons/green-dot.png'
    }
  } %}
  
  {{ craft.smartMap.map(locations, mapOptions) }}
  
  {# Loop through location entries #}
  {% for item in locations %}
  
    {% switch item.type %}
      {% case 'filmSites' %}
        {% set icon = '/assets/src/images/blue-marker.png' %}
      {% case 'castingCalls' %}
        {% set icon = '/assets/src/images/green-marker.png' %}
      {% default %}
        {% set icon = 'http://maps.google.com/mapfiles/ms/icons/green-dot.png' %}
    {% endswitch %}
  
    {% set address = item.address %}
  
    {# JS: Change marker icon #}
    {% includejs %}
  
      var markerId = 'smartmap-mapcanvas-1.{{ entry.id }}.address';
      smartMap.marker[markerId].setOptions({'icon': '{{ icon }}'});
  
    {% endincludejs %}
  
  {% endfor %}
  
  ```
  
  **Tags:** plugin-smartmap
  
  > **Comments:**
  > **username_1**: I'm impressed... I only added that page to the documentation 2 days ago. ;)  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2016-01-04. Score: 2 | Accepted answer
  
  I believe the problem is in this line of code:
  
  ```
  var markerId = 'smartmap-mapcanvas-1.{{ entry.id }}.address';
  
  ```
  
  Because you're generating markers from **matrix blocks**, you'll need to use the *block* ID instead of the entry ID. In your case, that may looks something like this:
  
  ```
  var markerId = 'smartmap-mapcanvas-1.{{ item.id }}.address';
  
  ```
  
  > **Comments:**
  > **username_0**: This was indeed the source of my problem, thank you very much!  
  
  ---
  
  