Export custom Google Maps as KML files, using Google Apps Script
Export custom Google Maps as KML files, using Google Apps Script.
This script can be used to automatically bulk-export a collection of public,
user-generated Google Maps maps as KML files. They are stored in a specified
Google Drive directory, where they can be easily downloaded or shared.
NOTE: All maps being exported must have “link sharing” enabled.
This option can be found under the “Share” options in the ‘My Maps’ editor
interface. The “Public: everyone on the internet can find and access” option
does not need to be enabled.
This script is designed to be run on-demand via the GAS interface, or
periodically via GAS triggers. For more info on setting up GAS triggers, see
this Google Apps Script guide.
To execute the script, simply run the main()
function.
There are two basic steps necessary to run this script.
config.js
should contain a single JavaScript object, used to specify all
necessary configuration information. Here’s where you specify details about
the maps to be backed up, as well as the Google Drive directory to save the KML
files to.
An example version is provided, named example.config.js
, which can be
renamed or copied to config.js
before loading into the GAS project.
The basic structure can be seen below.
const config = {
"mapList": [
{
"name": "<map name>",
"id": "<Google Maps map ID>"
}
],
"backupDir": "<Google Drive directory ID>"
};
mapList.name
: An arbitrary map name, used as the exported filename.mapList.id
: The ID of the map, which can be found in the map’s sharablemid=XYZ
.backupDir
: The ID of the Google Drive directory, where exported mapsYou can manually load the script into a
new GAS project,
by simply copying and pasting it into the editor.
Or you can use a
tool like clasp
to upload it directly. For more information on using clasp, here is a
guide I found useful.