Skip to content

Google Map ​

The page contacts-classic.html has a Google Map beside the studio's address. Out of the box it shows a picture in its place and loads nothing from Google: the map needs a Google Maps key of your own, set once in js/config.js.

How to access ​

HTML/js/config.js

js
  /**
   * Google Maps on the Contacts page: an API key from the Google Cloud console with the Maps
   * JavaScript API enabled, restricted to this site's domain (Credentials, the key, Website
   * restrictions). Leave it empty to go without: the map's picture stays and nothing loads from Google.
   */
  googleMapsKey: '',

Getting a key ​

▶️ Step 1. ​

In the Google Cloud console, choose or create a project and enable the Maps JavaScript API for it, as Google's set-up guide walks you through.

▶️ Step 2. ​

On the Google Maps Platform's credentials page, create an API key, and under its API restrictions keep Maps JavaScript API.

▶️ Step 3. ​

Open the key and restrict it to your site: under its application restrictions, choose Websites and add your domain, such as https://example.com/*, and the same with www. if your site answers there too. A key that works from any site can be copied from your page and used by anyone, on your bill.

▶️ Step 4. ​

Put the key in js/config.js:

js
  googleMapsKey: 'YOUR-KEY',

Reload contacts-classic.html: the map loads as it scrolls into view, in place of the picture. If Google refuses the key, its error shows in the map's place: a site that is missing from the key's websites is the usual cause.

Loading the map only when asked ​

HTML/js/config.js

With googleMapsLoadMode set to 'click', the map stays a picture with a Load map button, and nothing is sent to Google until the visitor presses it. Choose it when your privacy rules, such as the GDPR, ask for the visitor's consent before a third party is contacted.

js
  googleMapsLoadMode: 'click',
With 'click', the map waits for the visitor to press Load map

Moving the marker ​

contacts-classic.html → data-arts-component-name="GoogleMap"

The map's place is in its options: the marker's latitude and longitude, and the zoom. The marker's title is in the <template> after the map:

html
<div
  class="google-map js-google-map"
  data-arts-component-name="GoogleMap"
  data-arts-component-options='{"mapId":"","zoom":14,…,"markers":[{"lat":41.3889,"lng":2.176,"icon":null}],…}'
>
…
<template class="js-google-map__info" data-marker-index="0">
  <div class="google-map__info">
    <p class="google-map__info-title js-google-map__info-title">Velum Studio</p>
  </div>
</template>

Keep the options valid JSON: How a page is built shows what to keep as it is.

Next: Before launch.