Friday, July 23, 2010

Google Maps API for Flash at Progressive Insurance Automotive X PRIZE

The following is a guest blog post by Kevin MacDonald of ThinkWrap Solutions

We're coming to you live from the Michigan International Speedway, where the Progressive Insurance Automotive X PRIZE (PIAXP) competition is underway.

This competition will award $10 million in prizes to the teams that win a rigorous stage competition for clean, production-capable vehicles that exceed 100 MPG energy equivalent (MPGe).

Vehicles are equipped with telemetry sensors and a GPS that together capture the following key performance indicators (KPI): fuel consumption, CO2 emissions, carbon footprint, speed, distance travelled and location.

ThinkWrap Solutions partnered with PIAXP to build a web experience that lets you monitor these KPI -- second-by-second -- from the comfort of your web browser.

The web-based experience is centered around a dashboard, a Flash application that embeds a number of telemetry gadgets, each responsible for the display of one KPI.

A Google Map is central to this experience, which uses a combination of location and horizontal dilution of precision (HDOP) to show the vehicle's movement around the track.

It's quite a novelty to be present at the Speedway, to watch the vehicle's icon round a turn on the map -- and then look away from the browser and to the track to see the actual vehicle approach and pass by.

To enjoy this experience, visit the official website, to meet the teams and their vehicles. (Check this video to see the map and telemetry data in action.)

Race times and vehicles are updated daily and posted at this page. Click on one of the vehicle photos on this page to view its telemetry data, and track its progress as it races around the racetrack, live on a Google Map!

Challenges

Our first challenge was to make sure that the map accurately tracks the vehicle's movement around the track. Although a GPS reports latitude and longitude coordinates to a precision of a few feet, availability of GPS satellite signals and atmospheric conditions can affect coordinate accuracy. Without concern for this accuracy, the map might show a vehicle hopping around the track, up on to the stands, over the stands and into a nearby farmers field!

We all know that GPS coordinates include latitude and longitude. GPS also measure the accuracy of these horizontal coordinates through a metric called Horizontal Dilution of Precision (HDOP) which for us, varies from 1 to 50 (1 is best and 50 is worst).

The map plots the coordinates on the map only if HDOP is 3 or less. If it's greater, the vehicle icon does not move. After 30 seconds, the icon is removed from the map.

Another challenge was to economically satisfy the clients' real-time demand for data, especially under conditions where a media blitz attracts tens or hundreds of thousands of visitors. Data flow -- from vehicle to website -- involves many intermediate stages: each vehicle independently broadcasts its KPI through a Sprint cellular connection, second-by-second, to a central server. Every second, this server batches KPI records across all reporting vehicles, and pushes, as a POST request, through a REST interface to a Java-based server running on Google App Engine. This server then caches the data in memory, and stores a copy in Datastore.

Client applications, which display the dashboard, poll for new data from Google App Engine through another REST interface. If the request hit the servlet that originally received the KPI from the vehicles, the request is serviced from a cache. Otherwise, the servlet needs to query the Datastore, cache the data and then reply to the client.

The client receives a batch of KPI data for the last 10 or so seconds, which it plays back through the dashboard, one record per second. When the client's buffer is nearly empty, it requests another batch of new data and continues, rinse-cycle-repeat.

Although the clients play back KPI data from a few seconds ago, collectively, they place much less burden on the server, and maintain sufficient buffer so as to minimize interruptions when updating the map.

We built our map on the Google Maps API for Flash platform, primarily due to the maturity of its software development kit (Flex Builder), relative ease of development, and cross-browser support.

Enjoy!