Answers.Body: <p>Icon management is handled a bit differently in the new Google Maps plugin. Now, you set icons <em>before</em> the map is rendered, even in Twig!</p>
  <ul>
  <li><em>Official guide for <a href="https://plugins.doublesecretagency.com/google-maps/guides/setting-marker-icons/" rel="nofollow noreferrer">Setting Marker Icons</a></em></li>
  </ul>
  <pre><code>{# Get all bars &amp; restaurants #}
  {% set bars        = craft.entries.section('locations').type('bars').all() %}
  {% set restaurants = craft.entries.section('locations').type('restaurants').all() %}
  
  {# Create a dynamic map (with no markers) #}
  {% set map = googleMaps.map() %}
  
  {# Add all bar markers #}
  {% do map.markers(bars, {
      'icon': '/images/bar-icon.png'
  }) %}
  
  {# Add all restaurant markers #}
  {% do map.markers(restaurants, {
      'icon': '/images/restaurant-icon.png'
  }) %}
  
  {# Display map #}
  {{ map.tag() }}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-03-16T14:30:50.670Z
Answers.Text: Got it — I see how to add the infowindow via options, but in this case, how do I pass those options to the set map = googleMaps.map() without an array of locations?
Answers.UserDisplayName: Charlie Triplett
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-03-17T03:31:43.397Z
Answers.Text: `googleMaps.map([], options)` - Skip the first parameter by passing in an empty array.
Answers.UserDisplayName: Lindsey D
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-03-15T17:13:22.707Z
Answers.LastActivityDate: 2021-03-15T17:13:22.707Z
Answers.UserDisplayName: Lindsey D
Body: <p>There's something that I'm missing in the migration from smartMaps to GoogleMaps. I have a series of points that represent different types/outcomes/modes of transportation crashes. I'm setting options on the markers and then trying to push that back into the googleMaps markers.</p>
  <p>This worked with smartMaps but my JS-skillz are not super strong and I'm getting an error:
  Example:
  Uncaught TypeError: Cannot read property 'mapAlpha.5981.address' of undefined</p>
  <p>What am I missing here?</p>
  <pre><code> {% set locations = craft.entries.section('crashes').all() %}
  
    {% set options = {
      id: 'mapAlpha'
    } %}
  
    {{ googleMaps.map(locations, options).tag() }}
  
    &lt;script&gt;
  
      var crashMarkers = Array();
  
      {#  Loop through entries and add settings to markers #}
      {% for entry in locations %}
        var markerId = 'mapAlpha.{{ entry.id }}.address';
  
        // Uncaught TypeError: Cannot read property 'mapAlpha.5981.address' of undefined
  
        googleMaps.marker[markerId].setOptions(
            {
                'icon': '{{ icon }}',
            }
        );
  
        crashMarkers.push(googleMaps.marker[markerId]);
  
      {% endfor %}
  
  &lt;/script&gt;
  </code></pre>
  
Tags: <plugin-googlemaps>
Title: GoogleMaps plugin marker setOptions error
ThreadText: # GoogleMaps plugin marker setOptions error
  
  (Asked by: username_0 on 2021-03-15)
  
  There's something that I'm missing in the migration from smartMaps to GoogleMaps. I have a series of points that represent different types/outcomes/modes of transportation crashes. I'm setting options on the markers and then trying to push that back into the googleMaps markers.
  
  This worked with smartMaps but my JS-skillz are not super strong and I'm getting an error:
  Example:
  Uncaught TypeError: Cannot read property 'mapAlpha.5981.address' of undefined
  
  What am I missing here?
  
  ```
   {% set locations = craft.entries.section('crashes').all() %}
  
    {% set options = {
      id: 'mapAlpha'
    } %}
  
    {{ googleMaps.map(locations, options).tag() }}
  
    <script>
  
      var crashMarkers = Array();
  
      {#  Loop through entries and add settings to markers #}
      {% for entry in locations %}
        var markerId = 'mapAlpha.{{ entry.id }}.address';
  
        // Uncaught TypeError: Cannot read property 'mapAlpha.5981.address' of undefined
  
        googleMaps.marker[markerId].setOptions(
            {
                'icon': '{{ icon }}',
            }
        );
  
        crashMarkers.push(googleMaps.marker[markerId]);
  
      {% endfor %}
  
  </script>
  
  ```
  
  **Tags:** plugin-googlemaps
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2021-03-15. Score: 2 | Accepted answer
  
  Icon management is handled a bit differently in the new Google Maps plugin. Now, you set icons *before* the map is rendered, even in Twig!
  
  * *Official guide for [Setting Marker Icons](https://plugins.doublesecretagency.com/google-maps/guides/setting-marker-icons/)*
  
  ```
  {# Get all bars & restaurants #}
  {% set bars        = craft.entries.section('locations').type('bars').all() %}
  {% set restaurants = craft.entries.section('locations').type('restaurants').all() %}
  
  {# Create a dynamic map (with no markers) #}
  {% set map = googleMaps.map() %}
  
  {# Add all bar markers #}
  {% do map.markers(bars, {
      'icon': '/images/bar-icon.png'
  }) %}
  
  {# Add all restaurant markers #}
  {% do map.markers(restaurants, {
      'icon': '/images/restaurant-icon.png'
  }) %}
  
  {# Display map #}
  {{ map.tag() }}
  
  ```
  
  > **Comments:**
  > **username_0**: Got it — I see how to add the infowindow via options, but in this case, how do I pass those options to the set map = googleMaps.map() without an array of locations?  
  > **username_1**: `googleMaps.map([], options)` - Skip the first parameter by passing in an empty array.  
  
  ---
  
  