Accessibility

Developer Center Article

Using GPS

The GPS (Global Positioning System) is a "constellation" of 24 well-spaced satellites that orbit the Earth and make it possible for people with ground receivers to pinpoint their current geographic location. The location accuracy is anywhere from 100 to 10 meters for most equipment, however, military equipment is even more accurate (down to about 1 meter or less). GPS measures coordinates such as latitude, longitude, elevation, date, and time and provides them as string values. Here's an example of the type of information a GPS receiver provides:

160303 154500 42.35124 -71.07788
160303 – the date (March 16, 2003)
154500 – the time (3:45:00 PM GMT)
42.35124 – the latitude
-71.07788 – the longitude

So what does this mean for Macromedia Flash developers? Well, if you look at the PDA landscape and all of the peripheral devices, you'll get an idea of some of the different things which may be possible. In this case, the Nature and Inquiry group thought of a PDA-based application that would use GPS technology and Macromedia Flash for a public art work, and Smart Worlds formalized the idea with a technology.

Some developers had worked on aspects of these ideas before, but did not realize them the extent of the Invisible Ideas project. In 2002, Phillip Torrone of Flash Enabled created a demo Macromedia Flash application for Pocket PCs which used a GPS receiver and displayed movie trailers as he approached certain movie theatres. This was a cool demo; it opened the door of possibilities for a much larger and robust application, Invisible Ideas.

Invisible Ideas extends the possibilities for user interaction with a Macromedia Flash application. Users walk around an outside physical environment to view artist content; the users' locations (measured in latitude and longitude), combined with an artist ID, trigger events in Macromedia Flash.

C++ Application

There's no way Macromedia Flash can communicate directly with a GPS receiver, so we needed to develop a gateway to make the application work. The gateway acted as a bridge between the GPS receiver and the Macromedia Flash application by providing the raw GPS information we needed through APIs (Application Programming Interface). This gateway was a custom C++ application that Ron Wallace created that resided on the Pocket PC. Its file size is only 37K.

One concern Ron had when creating the gateway was that we needed to have the C++ code read and interpret the GPS coordinates efficiently so we could save CPU cycles for Macromedia Flash Player functions. The gateway code performs the following functions:

  • Continuously gives the current position (up to once per second)
  • Returns the status of satellites in view and their signal strengths
  • Reads a series of waypoints from a text file
  • Continuously returns which waypoint is nearest to the current position, and how near it is (in feet)
  • Stores tracking information in a log file (Invisible Ideas uses this to draw a map that shows the paths where each participant walked.)

We designed the code to work with most Pocket PC devices and GPS receivers. However, there's one thing which we needed to initially control through Macromedia Flash—specifying the COM port on the device. The COM port setting tells the gateway code what communication port on the Pocket PC to use to communicate with the GPS receiver.

Custom APIs for ActionScript

The C++ code Ron created provided several APIs which I could access with ActionScript. These included the following:

  • GPSOPEN comport: Initializes communication with the GPS receiver
  • GPSCLOSE: Terminates communication with the GPS receiver
  • GPSADDWAYPOINTS filename: Creates a series of waypoints from data contained in a text file
  • GPSADDWAYPOINT waypointname: Creates a single waypoint using the current position
  • GPSWRITEWAYPOINTS filename: Saves the current waypoint list to a file
  • GPSOPENTRACKLOG filename: Starts saving tracklog points to a file
  • GPSCLOSETRACKLOG: Stops saving tracklog points to a file
  • GPSGETFIX: Requests the latest date, time, latitude/longitude values from the GPS receiver
  • GPSGETNEAREST: Requests name, coordinates, and distance of the nearest waypoint
  • GPSGETSATINFO: Requests information about the visible satellites from the GPS
  • GPSSTART numseconds: Begins automatic updates of GPS messages every X seconds
  • GPSSETRADIUS feet: Sets the radius of sensitivity to waypoint detection

By referencing these APIs, I was able to create the overall functionality for the application, but it took a lot of testing and code tweaking to get it right. In the Macromedia Flash Application section, I'll describe it in more detail.

Track Logs Feature

Another unique feature of Invisible Ideas is the ability for users to view their walking path on a scaled map on a web-based Macromedia Flash application. To make this possible, the C++ code incrementally saves the data to an updated text file containing the GPS information of the user from start to finish. Here's a sample log file:

031603 104840 42.35166 -71.07820
031603 104901 42.35165 -71.07822
031603 104922 42.35173 -71.07826
031603 104943 42.35187 -71.07834
031603 105003 42.35187 -71.07835
031603 105023 42.35188 -71.07834
031603 105043 42.35189 -71.07832
031603 105103 42.35187 -71.07834

The C++ code saves the information to a file called tracklog.txt, which is stored on a removable SD media card. When a user returns the Pocket PC to the gallery, the staff removes the SD card and uploads the text file to a server. Each time a user starts the Invisible Ideas application, it erases the contents of the tracklog.txt file and starts writing new data to it.

Giuseppe Taibi created an application that takes the latitude and longitude information from the text file and applies an algorithm to convert the data to X,Y screen coordinates that correspond to a scaled map. Giuseppe's goal was to have a PHP call that returns an XML file with information about the user, followed by the list of the entire X, Y coordinates.

<XMLtracepoints>
	<visitor ID="1" name="Julie Ayres" email="julie@foo.com" date="121169">
		<waypoint timestamp="1435" x="656" y="96">
		</waypoint>
		<waypoint timestamp="1435" x="652" y="85">
		</waypoint>
		<waypoint timestamp="1436" x="642" y="69">
		</waypoint>
		<waypoint timestamp="1437" x="629" y="61">
		</waypoint>
		<waypoint timestamp="1438" x="613" y="70">
		</waypoint>
	</visitor>
</XMLtracepoints>

This XML data is sent to the web-based Macromedia Flash application. This application plots the path using the drawing API function in ActionScript. Giuseppe also created an easy-to-use PHP-based administration tool for naming and uploading these tracklog files.

‹ Back | Contents | Next ›

 

Submit feedback on our tutorials, articles, and sample applications.