Locations

Whether you are working with dynamic maps or static maps, you'll need to specify the locations that you want to appear on the map. You'll most often encounter this parameter when you create a map or add markers to a map.

What are "locations"? They can be any of the following...

# Coordinates

The locations value can be a set of coordinates, or an array of coordinate sets.

// Just one set of coordinates
var locations = {
    'lat':  32.3113966,
    'lng': -64.7527469
};

// An array of coordinate sets
var locations = [
    {'lat': 37.2430548, 'lng': -115.7930198},
    {'lat': 57.3009274, 'lng':   -4.4496567}
];

In JavaScript, you may only use Coordinates

If you are working in JavaScript, then your only option is to work with coordinates. It is physically impossible to translate Address Models and Elements into JavaScript.


# Address Models

The locations value can be set as an individual Address Model, or as an array of Address Models.

{# Just one Address Model #}
{% set locations = entry.myAddressField %}

{# An array of Address Models #}
{% set locations = [
    entry.homeAddress,
    entry.businessAddress
] %}

# Elements

The locations value can be set as an individual Element, or as an array of Elements. This can include any native Element Types (ie: Entries, Categories, Users, etc), as well as any custom Element Types introduced by other plugins or modules.

{# Just one Element #}
{% set locations = entry %}

{# An array of Elements #}
{% set locations = craft.entries.all() %}

Elements must have a valid Address field

When using an Element, ensure that it has at least one Address field attached to it. The plugin will automatically render all valid addresses on the map.