objectivehtml / Google-Maps-for-Craft

The complete geolocation toolkit for Craft CMS.
Other
94 stars 20 forks source link

Centering map and setting marker with dynamic fields #66

Open iamtompickering opened 8 years ago

iamtompickering commented 8 years ago

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) }}