Overview
The training code integrates the Google Maps Static API to display a map image for a log entry's GPS coordinates. The current code has an empty GOOGLE_MAPS_STATIC_API_KEY constant. Since June 2018, Google has required a valid billing-enabled API key for all Maps API requests — unauthenticated requests return an error image. The training must be updated to document how to obtain a key and configure it safely.
Background
What Changed in 2018
Google's Maps Platform pricing change (June 2018) made API keys mandatory and introduced per-request billing. Requests without a valid key return a watermarked "For development purposes only" image and are rate-limited to near zero.
Current Code
const
GOOGLE_MAPS_STATIC_API_KEY = ''; // <-- empty, broken
procedure LoadMapImage;
var
URL: string;
begin
URL := Format('https://maps.googleapis.com/maps/api/staticmap?center=%g,%g&zoom=15&scale=2&size=600x300&key=%s',
[Lat, Lon, GOOGLE_MAPS_STATIC_API_KEY]);
// HTTP GET to load image...
end;
Recommended Approach for Training
- Document the steps to create a Google Cloud project, enable the Maps Static API, and create an API key restricted to the Maps Static API.
- Store the key in a separate configuration file (
config.pas or a text resource) that is excluded from source control via .gitignore — teaching good secrets hygiene.
- Provide a fallback path if no key is configured: display a placeholder image and a message directing the student to configure a key, rather than making a failing HTTP request.
- Alternatively, offer OpenStreetMap Static Maps (via
staticmap.openstreetmap.de or Maps for Free) as a no-key fallback for the training exercise.
Files Affected
lab-src/Lab*/units/ (wherever GOOGLE_MAPS_STATIC_API_KEY is defined)
lab-src/Lab*/forms/formMain.pas (map image load call)
lab-src/Lab*/frames/uEntryDetailsFrame.pas (if map is displayed there)
New file: lab-src/Lab*/units/config.pas (API key configuration, git-ignored)
.gitignore (add config.pas or key file)
Steps to Address
- Move
GOOGLE_MAPS_STATIC_API_KEY out of the main source into a separate config.pas file:
unit config;
interface
const
GOOGLE_MAPS_STATIC_API_KEY = ''; // Fill in your key
implementation
end.
- Add
config.pas to .gitignore and provide a config.pas.template in its place.
- Add a check before the API call:
if GOOGLE_MAPS_STATIC_API_KEY = '' then
begin
imgMap.Visible := False;
lblMapNote.Text := 'Configure Google Maps API key in config.pas to see map';
Exit;
end;
- Update lab instructions with step-by-step instructions to get a Maps Static API key from Google Cloud Console.
- Optionally add an OpenStreetMap tile-based fallback for students who do not want to set up billing.
Test Plan
Overview
The training code integrates the Google Maps Static API to display a map image for a log entry's GPS coordinates. The current code has an empty
GOOGLE_MAPS_STATIC_API_KEYconstant. Since June 2018, Google has required a valid billing-enabled API key for all Maps API requests — unauthenticated requests return an error image. The training must be updated to document how to obtain a key and configure it safely.Background
What Changed in 2018
Google's Maps Platform pricing change (June 2018) made API keys mandatory and introduced per-request billing. Requests without a valid key return a watermarked "For development purposes only" image and are rate-limited to near zero.
Current Code
Recommended Approach for Training
config.pasor a text resource) that is excluded from source control via.gitignore— teaching good secrets hygiene.staticmap.openstreetmap.deorMaps for Free) as a no-key fallback for the training exercise.Files Affected
Steps to Address
GOOGLE_MAPS_STATIC_API_KEYout of the main source into a separateconfig.pasfile:config.pasto.gitignoreand provide aconfig.pas.templatein its place.Test Plan
config.pasis listed in.gitignoreand does not appear ingit statusoutput after being created.config.pas.templateexists in the repo with an empty key and instructions comment.