Git Product home page Git Product logo

Comments (13)

keithmancuso avatar keithmancuso commented on August 12, 2024

the trick is to realize that each map field can have a number of different markers in it.. assuming you just have one marker in the map field it would be something like this

{% set options = { id: 'map', width: '400px', height: '300px' } %}
{{ craft.googleMaps.map(options) }}

{% for marker in entry.yourCustomMapField.getMarkers() %}
{% set lat = marker.lat %}
{% set lng = marker.lng %}
{% endfor %}

{{ craft.googleMaps.center('map',lat, lng) }}

Iif you just want to output the map for an entry is to use the field directly so just this, and it will automatically center on that marker

{% set options = { id: 'map', width: '400px', height: '300px' } %}
{{ craft.googleMaps.map(options) }}
{{ craft.googleMaps.data('map', entry.yourCustomMapField) }}

from google-maps-for-craft.

mediagirl avatar mediagirl commented on August 12, 2024

Is this list of variables documented somewhere "marker.lat" and "marker.lng"?

from google-maps-for-craft.

keithmancuso avatar keithmancuso commented on August 12, 2024

I dont think they are fully documented yet. I just went into the plugin files, in "models" theres GoogleMaps_MarkerModel and GoogleMaps_MapDataModel. in both of those look for the "defineAttributes()" function that will list the properties of the model

from google-maps-for-craft.

keithmancuso avatar keithmancuso commented on August 12, 2024

ahh and he also has it written out in the wiki although there appears to be a typo as it says latitude vs lat
https://github.com/objectivehtml/Google-Maps-for-Craft/wiki/Template-Reference#marker

from google-maps-for-craft.

mediagirl avatar mediagirl commented on August 12, 2024

Got it. I'll look there. Thank you! Was pulling my hair out yesterday trying to accomplish what I needed to accomplish for this project. Still having weird issues.

from google-maps-for-craft.

mediagirl avatar mediagirl commented on August 12, 2024

When I try this code on a location's detail page with my custom field name added, I get no output.

{% for marker in entry.map.getMarkers() %}
    {% set lat = marker.lat %}
    {% set lng = marker.lng %}
{% endfor %}

{{ lat }} {{ lng }}

Do you?

from google-maps-for-craft.

keithmancuso avatar keithmancuso commented on August 12, 2024

yup… is map your map fields handle?

Have you turned on geocoding ?

Geocoding has to be enabled in the plugin settings and you note which fields make up the address to geocode or on the field settings if you want it to geocode it as you edit the entry.

from google-maps-for-craft.

mediagirl avatar mediagirl commented on August 12, 2024

Yes, "map" is my field's handle.

GeoCoding is on in plugin settings and I'm running the latest version #0.7.1

The fields that make up the address are set at the plugin level and the field level and the entry's marker is correctly set and saved in the DB.

I can get the map to show up on the detail page using this code but I want to control the zoom level and cannot do that using map() or data():

                {{ craft.googleMaps.map({
                    id: 'locationmap',
                    width: '385px',
                    height: '300px',
                    options: {
                        scrollwheel: false
                    }
                }) }}
                {{ craft.googleMaps.data('locationmap', entry.map) }}

from google-maps-for-craft.

keithmancuso avatar keithmancuso commented on August 12, 2024

just use the zoom settings

https://github.com/objectivehtml/Google-Maps-for-Craft/wiki/Template-Reference#zoom

so add this

{{ craft.googleMaps.zoom('locationmap', 12) }}

from google-maps-for-craft.

mediagirl avatar mediagirl commented on August 12, 2024

I have tried that code and every other possible way to control the zoom. That code doesn't override the maps default zoom at all for me.

What works is setting "fitBounds: false" on map()... but then I need to get the marker's lat and long in order to center and zoom the map out... hence my question about how you get data out of the "geocoding'.

Will keep trying.

from google-maps-for-craft.

mediagirl avatar mediagirl commented on August 12, 2024

NOTE: I can get lat & lng printing out in the template if I move the variables inside the for loop:

{% for marker in entry.map.getMarkers() %}
    {% set lat = marker.lat %}
    {% set lng = marker.lng %}
    {{ lat }} {{ lng }}
{% endfor %}

from google-maps-for-craft.

mediagirl avatar mediagirl commented on August 12, 2024

ALAS... This finally worked!

{% for marker in entry.map.getMarkers() %}
    {{ craft.googleMaps.marker('locationmap', {
        lat: marker.lat,
        lng: marker.lng,
        fitBounds: false
    }) }}
    {{ craft.googleMaps.zoom('locationmap', 13) }}
    {{ craft.googleMaps.center('locationmap', marker.lat, marker.lng) }}
{% endfor %}

Keith, a sincere THANK YOU!

from google-maps-for-craft.

objectivehtml avatar objectivehtml commented on August 12, 2024

Yup, thanks the way to do it. Thanks for the help Keith. Out of town on vacation this week with limited access to Internet.

from google-maps-for-craft.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.