Term maps no longer rendering with Code field due to changes in Maps API key requirements
|Category:||Web service API|
|Google Code Legacy ID:||Tested version:||2.5|
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.
- 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)
- Broken link, no map displays
- Console reports: "Failed to load resource: the server responded with a status of 403 ()"
- Map is generated based on coordinates
<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¢er='.$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.