Bug #13063

Term maps no longer rendering with Code field due to changes in Maps API key requirements

Added by Dan Gillean over 2 years ago. Updated over 2 years ago.

Status:NewStart date:05/28/2019
Priority:MediumDue date:
Assignee:-% Done:

0%

Category:Web service API
Target version:-
Google Code Legacy ID: Tested version:2.5
Sponsored:No Requires documentation:Yes

Description

First reported in the User forum, 2019-05-27. Reproduced in 2.5 locally. See: https://groups.google.com/d/msg/ica-atom-users/KR5dq38X4oA/u-mIoOybBQAJ

There is a legacy feature in the terms, where data entered into the "Code" field would attempt to generate a static map. It would accept coordinate based lat/long values, or even keywords. See:

This feature was added in an early version and never integrated with the later Map additions that require an API key, such as the ability to add a map to Digital objects, or to a repository page.

As of 2016, it seems that Google no longer supports keyless calls to Maps. See:

Consequently, all attempts to generate a map from the Code field value now result in a broken link, even if a Google Maps API key has been added in the Settings.

To reproduce

  • Optional: add a Maps API key to Admin > Settings > Global
  • Create a new term or navigate to an existing term and enter edit mode
  • Add the following test coordinates to the Code field: 49.209261, -122.914882 (Artefactual HQ coordinates)
  • Save

Resulting error

  • Broken link, no map displays
  • Console reports: "Failed to load resource: the server responded with a status of 403 ()"

Expected result

  • Map is generated based on coordinates

Notes

The call is made here: https://github.com/artefactual/atom/blob/HEAD/apps/qubit/modules/term/templates/indexSuccess.php#L114

   <div class="field">
      <h3><?php echo __('Code') ?></h3>
      <div>
        <?php echo $resource->code ?>
        <?php if (!empty($resource->code) && QubitTaxonomy::PLACE_ID == $resource->taxonomy->id): ?>
          <?php echo image_tag('https://maps.googleapis.com/maps/api/staticmap?zoom=13&size=300x300&sensor=false&center='.$resource->code,
            array('class' => 'static-map', 'alt' => __('Map of %1%',
            array('%1%' => truncate_text(strip_markdown($resource), 100))))) ?>
        <?php endif; ?>
      </div>
    </div>

We can look at how the maps for the digital objects and repositories were updated to accept the key entered into the setting as a reference:

We should probably also review and update the find-repository-latlng task:

I've have set "Requires documentation" to Yes so we remember to update the various sections with a mention that an API key is required.

History

#1 Updated by Dan Gillean over 2 years ago

It would also be great to take this opportunity to make the map dynamic rather than static, if that won't introduce other unexpected issues (such as performance, etc).

Also available in: Atom PDF