Mapping AVC 2013 with Google Static Maps
Note: as of July 2018, Google Static Maps requires an API key. Links without an API key are now blocked and display an error message. For details, see Google's Static Maps API.
Most people are familiar with Google Maps, but perhaps you've never heard of Google's "Static Map" API, which is a way to embed maps as rendered images into a web page. For example, the following image is from Google Static maps and shows the parking lot at Boulder Reservoir where Sparkfun's 2013 AVC will take place.
The URL for this image encodes several factors, such as the center point of the map in GPS latitude and longitude values, zoom level, and many other useful features. The URL to produce the above image is:
http://maps.googleapis.com/maps/api/staticmap?center=40.071000,-105.229500&zoom=19&size=512x512&sensor=false&maptype=satellite
Breaking this down, you can observe that the Map is centered at 40.071000, -105.229500, is 512 x 512 pixels in size, and is set to zoom level 19, which is two below the maximum zoom availaable (21.) If you want to know more about generating images like this, see Google's Static Maps API. Using this API you can overlay markers to show the locations of things such as barrels, hoops and ramps. For example, here's an image that places 5 makers to show the center of the map as well as the 4 corners of a rectangle centered around this point:
The URL for this image looks like this:
http://maps.googleapis.com/maps/api/staticmap?center=40.071000,-105.229500&markers=color:blue|label:S|40.071000,-105.229500&markers=color:red|label:1|40.070900,-105.229400&markers=color:red|label:2|40.071100,-105.229400&markers=color:red|label:3|40.070900,-105.229600&markers=color:red|label:4|40.071100,-105.229600&zoom=19&size=512x512&sensor=false&maptype=satellite
Breaking this out, here's how the locations of the 5 markers are defined:
markers=color:blue|label:S|40.071000,-105.229500
markers=color:red|label:1|40.070900,-105.229400&
markers=color:red|label:2|40.071100,-105.229400&
markers=color:red|label:3|40.070900,-105.229600&
markers=color:red|label:4|40.071100,-105.229600
Building a Mapping Tool
Next, I decided to write a Java-based program that would download and cache the map data so I wouldn't need an internet connection to access it. As I worked on this code, it slowly took on new features, with the final result being able to:
Download and cache a set of maps (for the AVC and for the different locations I took my car to do test runs)
Display markers that indicate the location of the AVC obstacle placement (obstacles can also be moved and the overlay turned on and off)
Allow the placement of graphical waypoints which can then be dumped to a file, or uploaded to the car using a serial link
Click on a point to display its GPS coordinates
Calculate distances between points (in feet)
Here's a screen capture that shows the program in operation and displaying a Map of the AVC 2013 location with the location of the various obstacles indicated by different colored dots:
The tool palette at the top of the screen works like this:
Arrow - moves obstacles and waypoints around screen (also, hold shift and click waypoint to edit speed info)
Hand - scroll around map
Crosshair - click on a point to display its coordinates in the Info: box
Tape Measure - Click on one point, then another to display the distance, in feet, between these two locations
Push Pin - used to place a waypoint
Trash Can - click to delete a waypoint (cannot delete obstacles)
In addition, the menus at the top provide various options, as follows:
File
Open Map
Create Map
Quit
Zoom
19
20
21 (most detail)
Options
Show Obstacles (on/off)
Move Obstacles (on/off)
Show Waypoint Numbers (on/off)
Reset Obstacles (resets to values defined in a utility file you can edit)
Ports
(shows available USB serial connections for upload to car)
Rescan Ports (rebuilds list of ports)
Coords
Upload to Car (sends to car using hex ascii protocol
Save Coords as... (saves to comma separated file)
Load Coords (loads from comma separated file)
Coord Report (displays distances from each to waypoint to the next)
Show Coords (displays coord data in a pop up text area)
Try it for Yourself
I've attached zipped copies of Mac and Windows executable files below along with the source code, but please read the following notes before you try using the code:
Mac users may need to set 32 bit mode for the app before it will run (select View Info on the unzipped GPSTileMap.app file then click the "Open in 32 bit mode" checkbox)
Windows users will need to rename the file to .zip before unzipping it (file contains a .bat file and I had to do this to get Google to allow me to upload it)
Window users will need to double click the GPSTileMap.bat file in the unzipped folder to run the app
The first time you run the app you'll have a blank Map. To generate a map for the AVC location (requires an Internet connection), select "Create Map" from the File menu and enter the following data:
Latitude: 40.071
Longitude: -105.2295
Declination: 9
Map Name: AVC
Then click OK. The code will then fetch a complete set of map tiles for all 3 zoom levels (may take several minutes depending upon the speed of your Internet connection.) Once downloaded, the data will be saved in the following location on your HD, depending on which OS you are using:
Windows: C:/Users/~user/Library/GPSTileMap/
Mac OSX ~/Library/Preferences/GPSTileMap/
However, you'll only need to know this should you need to delete a map. Normally, the last generated, or opened map should reopen automatically the next time you start the app.
Uploading Waypoints to Your Rover
I've also attached a simple Arduino sketch named CoordUploadExample.ino below that implements the protocol that runs on the car and receives and saves uploaded waypoint data. The code contains stub functions at the end of the that you will have to implement to make this code functional. To give you an example of how this code works, here is an example of what the protocol looks like in action when uploading a series of 5 waypoints, along with a declination value of +9:
z
@0909
$0017E2640CC1472A400157
$0117E24E29C1473723015E
$0217E2576CC1474E81016C
$0317E269B3C14741EE0172
$0417E2666AC14733280161
And, here the same waypoint data as shown by the "Show Coords" menu selection:
40.0712717,-105.2300736,1
40.0707113,-105.2297437,1
40.0709484,-105.2291456,1
40.0714164,-105.2294675,1
40.0713322,-105.2298456,1