1

I'm getting started with the Google Maps plugin. I have experience with the EE version but not understanding some of the Craft version. I'm trying to output a set of markers from entries. Currently nothing outputs at all.

I imported all the addresses and then added a GoogleMap field to the entries. When I check the entries it all looks correct.

I have:

{% set options = {
    id: 'map', 
    width: '950px', 
    height: '500px',
} %}

{{ craft.googleMaps.map(options) }}
{% for entry in craft.entries.section('maps').limit(10) %}

    {{ craft.googleMaps.data('map', entry.mapData) }}

{% endfor %}

I also tried this for the markers:

{% for entry in craft.entries.section('maps').limit(100).find() %}
    <!-- {{ entry.title }} -->
    {% set marker = {
        address: '{{ entry.mapData }}',
        content: '{{ entry.title }}',
        clustering: true
    } %}
    {{ craft.googleMaps.marker('map', marker) }}

{% endfor %} 
1

Your first example essentially looks correct — and I don't know if it makes a difference, but the syntax that I have used in the past looks something like this, where I output the map after setting the data.

{% set options = {
    id: 'map', 
    width: '950px', 
    height: '500px',
} %}

{% set map = craft.googleMaps.map(options) %}

{% for entry in craft.entries.section('maps').limit(10) %}
    {{ craft.googleMaps.data('map', entry.mapData) }}
{% endfor %}

<div class="map">
    {{ map }}
</div>
| improve this answer | |
  • Thanks for sharing that code. Didn't make a difference on my end though. No markers output - just the map html. <div id="oh-map-map" class="oh-google-map-canvas" style="width:950px;height:500px"></div> – glider May 8 '15 at 18:55
  • hmmm... strange. Granted in my use-case I had all the markers defined in a single entry/map, but I don't see why it would make a difference if you're grabbing markers from multiple maps. I assume you are using the 'add marker' button on the map(s) in the CP, and then setting the marker(s) based off the address? – Douglas McDonald May 8 '15 at 19:14
  • Might start with some generic code and then replace it with your dynamic data. Perhaps the marker graphic itself is not styled correctly, and thus not showing up. – Douglas McDonald May 8 '15 at 19:21
  • No I'm not manually plotting each entry. I imported 500 records with address, city, state, zip. When I setup the map field I defined each of those to pull the data from. And like I said when look at an entry the map looks correct. Do I really have to manually plot the markers? Also nothing is output in the html except the map. In the EE version I can see all the markers output there. – glider May 8 '15 at 19:26
  • Not sure your setup, but sounds like you might want to look into just creating entries with fields for address, city, state, zip (vs. trying to import it into individual map field instances). And then grab that data to create the map/markers dynamically. What is 'mapData' exactly? Are you on 'craftcms.slack.com'? Might be easier to help you there. – Douglas McDonald May 8 '15 at 20:14
1

Thanks to Douglas I got code that works. Instead of trying to use a map field per entry I just need to output the address and have one map instance plot all the markers.

{% set options = {
    id: 'map', 
    width: '950px', 
    height: '500px',
    clustering: true,
} %}

{% set map = craft.googleMaps.map(options) %}

{% for entry in craft.entries.section('maps').order('title asc').limit(250) %}
    {% set marker = {
       address: entry.address ~ ', ' ~entry.city ~ ', ' ~ entry.state ~ ' ' ~ entry.zip, 
       content: entry.title
    } %}
    {{ craft.googleMaps.marker('map', marker) }}
{% endfor %}

{{ map }}
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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