Skip to main content

Google Static Maps

ProRequires Events Manager Pro. Compare plans

A static map is a picture of the map, with a marker on your location and your map style applied. It replaces the interactive map that #_LOCATIONMAP draws on location and event pages. Visitors who want to explore can click it, and you choose what the click does.

Static maps use Google's Maps Static API, which Google counts and prices separately from interactive maps. Google Map Types compares the three kinds.

Before you start
  • Maps already work on your site with a browser key. If not, start with Google Maps.
  • Events Manager Pro is active.

Set up static maps​

  1. In your Google Cloud project, enable the Maps Static API. See Enable the APIs.

  2. Get the two extra credentials described in API keys for static maps: a URL signing secret, which is always needed, and a server key, which is needed for caching and for maps sized in percentages.

  3. Go to Events then Settings then General then Google Maps and Location Services and set Google Map Type to Static. A Static Map Options group appears.

  4. Paste the signing secret into Google Maps API Secret Key and, if you have one, the server key into Google Maps API Server Key.

  5. Choose a Map click action and decide on caching. Both are explained below.

  6. Click Save Changes and view a location page. The map is now an image.

Static Map Options appear once the map type is Static. Key fields are blank here.

Static Map Options​

SettingDefaultWhat it does
Map click actionWhat happens when a visitor clicks the image. See Click actions.
Static hover textClick for interactive mapShown over the image when a visitor points at it, if the map has a click action.
Enable static map caching?NoKeeps a copy of each map image on your server. See Caching.
Static map cache expiry days28How long a cached image is kept before it is deleted.
Google Maps API Server KeyThe key your server uses to fetch images from Google.
Google Maps API Secret KeyThe URL signing secret for the Maps Static API.

API keys for static maps​

Static maps involve up to three credentials. The first is the browser key you already have.

CredentialWhere it goesWhen it is neededHow to restrict it
Browser keyGoogle Maps API Browser KeyAlways. Used when the visitor's browser loads the image straight from Google, and for any dynamic or embedded map a click loads.By website
URL signing secretGoogle Maps API Secret KeyAlways. Every static map address is signed with it, and Google rejects image requests whose signature is missing or wrong.Not applicable. Keep it private.
Server keyGoogle Maps API Server KeyWhen caching is on, or when a map's width or height is a percentage. In both cases your server fetches the image, not the visitor's browser.By your server's IP address, and to the Maps Static API

The signing secret is created per project in the Google Cloud console, in the Maps Static API's settings. Google's guide: Use a digital signature. Copy the secret exactly as Google shows it.

The server key is a second API key, made the same way as the first (see Create the key). A key restricted to your website's address won't work here, because a request from your server carries no page address. Restrict it to the IP address your server sends requests from, which your host can tell you.

Click actions​

Map click action offers six choices:

ChoiceOn click
No ActionNothing. The map is a plain image and no hover text shows.
Link to maps.google.com and center on coordinatesOpens Google Maps in a new tab at the location's coordinates
Link to maps.google.com based on location name and addressOpens Google Maps in a new tab, searching for the location's name and address
Link to maps.google.com based on only addressOpens Google Maps in a new tab, searching for the address
Load dynamic mapReplaces the image, in place and at the same size, with an interactive dynamic map using your style and balloon text
Load embedded mapReplaces the image with an embedded map, built according to Embed Display Type

The three link choices send the visitor to Google's own site and use none of your APIs. The two load choices count one dynamic or embedded map load, but only for visitors who click. Load embedded map needs the Maps Embed API enabled.

Caching​

With Enable static map caching? set to Yes, the first request for a map fetches the image from Google and saves it in wp-content/uploads/events-manager/static-gmaps/. Later visitors get the saved file from your own server, with no call to Google.

Things to know:

  • One file is saved per location and per size, so a location shown at two sizes has two files.
  • Once a day, files older than Static map cache expiry days are deleted, and the next visitor triggers a fresh copy.
  • Google's terms of service limit how long map content may be stored. Keep the expiry at 30 days or less. The default is 28.
  • A cached image is not refreshed when you edit the location. If you move a location's marker or change your map style, delete its files from the folder (their names start with gmap- and the location ID) or wait for them to expire.

Maps sized in percentages​

A map with a percentage width or height, such as #_LOCATIONMAP{100%,300px}, can't be requested until the page has loaded and its size in pixels is known. The page then asks your server for an image of that size, and your server fetches it from Google with the server key. Without caching this happens on every view and slows the map down, so switch caching on if your maps are sized in percentages.

Troubleshooting​

The map shows as a broken image
  • Check Google Maps API Secret Key. It must be the URL signing secret from the Maps Static API settings, not an API key.
  • Check that the Maps Static API is enabled on the project.
  • If caching is on or the map is sized in percentages, check the server key. A key restricted by website instead of IP address is refused.

Open the image's address in a new tab: when Google refuses a request it answers with a short message naming the reason.

Cached maps don't appear, or stay slow

Your server must be able to create and write to wp-content/uploads/events-manager/static-gmaps/. If you can upload to the Media Library, the permissions are normally right. Cached maps also rely on the first request for an image that doesn't exist yet reaching WordPress, so they won't be created if your uploads are served from another host, such as an offloaded media bucket or a CDN origin that isn't your site.

The map shows the old position after I edited the location

That is the cached image. Delete the location's files from the cache folder, as described under Caching.