Google-Maps-for-Craft icon indicating copy to clipboard operation
Google-Maps-for-Craft copied to clipboard

Geocoder seems to run each time, despite saved locations

Open Jammooka opened this issue 9 years ago • 1 comments

I have a map showing (ideally) every marker from within a channel of restaurants. There are a total of 80 markers across 76 entries. In the database, I can see 80 rows in craft_googlemaps_locations. From what I can tell, this means they've all been geocoded and so can just be output without needing to contact google on page load (and therefore avoid the limit).

Yet when I load the page, I only get a maximum of 11 markers. Searching the source for "new GoogleMaps.Marker" returns 80 results.

The code I'm using is:

{% set options =
    {
        id: 'map',
        width: '100%',
        height: '700px',
        options:
        {
            minZoom: 11
        }
    }
%}

{{ craft.googleMaps.map(options) }}


{% for restaurant in restaurants %}

    {% for marker in restaurant.address.getMarkers() %}

        {% set mrkrContent = 
            '<strong>' ~
            restaurant.title ~
            '</strong><br>' ~
            marker.address|replace({',': "<br>"})|raw
        %}

        {% set marker = 
            {
                address: marker.address,
                content: mrkrContent
            }
        %}

        {{ craft.googleMaps.marker('map', marker) }}

    {% endfor %}

{% endfor %}

Plugin settings are as follows: image

Am I doing something completely wrong?

Jammooka avatar Feb 29 '16 17:02 Jammooka

In case anyone has this same issue, I think it's to do with using "address". Presumably if there's a latlng parameter, you could pass that with the stored values, but I can't find any reference to that existing.

What I did instead was build an array of the data and then output it as JSON and just handled it all in the js.

{% set mapData = {} %}
{% for restaurant in restaurants %}
    {% for marker in restaurant.address.getMarkers() %}

        {% set mrkr = {
            'content'   :   '<strong>' ~ restaurant.title ~ '</strong>',
            'lat'       :   marker.lat,
            'lng'       :   marker.lng,
            'website'   :   restaurant.website,
            'opinion'   :   restaurant.opinion.first()|snake
        } %}

        {% set key = restaurant.slug ~ '-' ~ loop.index %}

        {% set mapData = mapData|merge({ (key) : mrkr }) %}

    {% endfor %}
{% endfor %}

<script>
    var mapData = {{ mapData|json_encode|raw }};
</script>

<div id="gmap" class="gmap js-gmap"></div>

Jammooka avatar Apr 29 '16 07:04 Jammooka