Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Geocoder seems to run each time, despite saved locations #54

Open
Jammooka opened this issue Feb 29, 2016 · 1 comment
Open

Geocoder seems to run each time, despite saved locations #54

Jammooka opened this issue Feb 29, 2016 · 1 comment

Comments

@Jammooka
Copy link

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
Copy link
Author

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>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant