Skip to main content

Maps and GPS tracks

Tuskfish can automatically generate maps of GPS tracks or points of interest via the Google Maps API. To enable this functionality you need to get an API key from Google and enter it in the Tuskfish Settings => Preferences. To create a map, select 'Track' as content type and upload your map data as media attachments (.kml or .kmz files) in the content entry form.

Creating a map

There are many ways to create a map - so long as you can export the map data as a .kml or .kmz file it should be fine (if your device exports .gpx, you can open that in Google Earth / Maps and re-export as .kml). For example, you can:

  • Record a track or waypoints on a GPS-capable device, which these days includes most smartphones (you may need an app) and many sports watches.
  • Create tracks and points of interest directly in Google Earth, Google Maps or Basecamp.

This demo track was recorded on my Garmin Forerunner 245 watch, and the points of interest were added in Google Earth.

Exporting a GPS track from a Garmin device

The watch automatically syncs with my phone via the Garmin Connect app, which in turn uploads data to the Garmin Connect website. I presume that most Garmin GPS devices will include similar functionality. To generate a .kml file of the GPS track:

  • Log in to Garmin Connect.
  • Select 'Activities' from the menu, open the relevant activity.
  • Click on the 'Settings' icon, which is a tiny cog on the right side of the page.
  • Select 'Export to Google Earth', to export the track as a .kml file.

If you have Google Earth installed (which you will need for the next step), opening the file will launch it and display the track.

Cleaning the track

The .kml is huge directly out of Garmin Connect because it contains all the tracking points and other guff that you don't need, which will cause the Google Maps API to complain. We just want the track. So to clean the file out:

  • Open the file in Google Earth.
  • In the 'Places' sidebar, select your 'Track' with a checkmark, and deselect 'Laps' and 'Tracking points'.
  • From the menu, select 'File' => 'Save' => 'Save place as' to re-export the cleaned file.

That will give you a very small KML file with all the rubbish removed. For this track, the original KML file was 2.9 MB and the cleaned one is less than 7 KB!

You can also clean the file with Google Maps, which is slightly more complicated:

  • Login to Google Maps.
  • Select the menu icon, 'Your places' and then the 'My places' tab, 'Create map' and 'Import'. This will open a dialogue box for uploading your KML file.
  • Now deselect all the layers except for 'Track'.
  • Open your new Google Map, click on the 'Layer options' menu (three dots to the right of the track layer) and select 'Export data' => KML/KMZ.

Please note that you need to get a Google Maps API key and enter it in Tuskfish Preferences to use this functionality.

Changing the default map behaviour

You can change the default map behaviour by editing the Javascript snippet in the track.html template. Please refer to the Google Maps API documentation.

<script>
  var map;
  function initMap() {
    map = new google.maps.Map(document.getElementById('map'), {
      mapTypeId: google.maps.MapTypeId.SATELLITE,
      zoom: 14
    });

    var src = '<?php echo TFISH_MEDIA_URL . xss($content->media()); ?>';

    var kmlLayer = new google.maps.KmlLayer(src, {
        suppressInfoWindows: false,
        preserveViewport: false,
        map: map
      });
  }
</script>

Alternatives

In principle, you should be able to swap out Google Maps for any other Javascript-based mapping service simply by replacing the code snippet in the track.html template. You might need to whitelist more media file types if the alternative service uses an alternative file format such as .gpx.

Sadly, Google has made a once simple signup process to get an API key so excruciating as to be almost comical by strapping it to the bloated Google Cloud platform. I will be looking into alternative, free or low-cost alternatives. So far I haven't found a free one that includes satellite imagery, which is important to me (if you're bushwalking you need to know what kind of vegetation you're dealing with, if the river actually has water in it and so on). If you know of one please let me know.

Copyright, all rights reserved.