Skip to content

Centering map and setting marker with dynamic fields #66

@iamtompickering

Description

@iamtompickering

I'm trying to set the center of the map and a marker from some plain text fields in the entry but it doesn't seem to recognise the fields in the settings. When I replace the entry.locationLatitude and entry.locationLongitude with actual values it works fine, but these need to be dynamic per entry. Is this possible and if so please could you let me know how this can be done as I cannot find it anywhere in the documentation.

{% set options = {
    id: 'map', 
    width: '100%', 
    height: '250px',
} %}

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

{% set marker = {
    id: 'map',
    data: {
        latitude: entry.locationLatitude,
        longitude: entry.locationLatitude
    }
} %}

{{ craft.googleMaps.center('map', entry.locationLatitude, entry.locationLongitude) }}
{{ craft.googleMaps.marker('map', marker) }}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions