Wednesday, June 4, 2008

Simulating Driving on Google Maps: Using Flash for a Faster & Smoother Experience

Hi! I'm Katsuomi Kobayashi, a developer from Osaka, Japan. I'm delighted to write as a guest on this blog.

2D Driving Simulator on Google Maps is a personal project of mine. With the power of Google Maps, you can drive around the world without having to worry about spending money on expensive gas. And it is using the brand-new Flash API which Google released two weeks ago.

My original 2D Driving Simulator is a Flash toy that simulates car parking and trailer movement. In my second release of the toy, I added in wide courses to make it a bit more fun (and less crash-prone). When I tried to add in more natural courses and realized how difficult it was, I decided to test out using the real roads of Google Maps as a backdrop.

At the time of that decision, the Google Maps API was only available in Javascript - so I actually had to find a way to overlay the Flash toy on top of a Javascript map and synchronize them. Amazingly, it actually somewhat worked. Unfortunately, it's 'success' relied on the troublesome wmode=transparent Flash parameter, and on having to call JavaScript from Flash 20 times a second (certainly not a typical thing to do).

So, the release of the Google Maps API for Flash was truly happy news for me. I implemented it right away. It was easy to replace the JS API; it only took a few hours. All I had to do was to add a com.google.maps.Map child on the main Sprite, copy the JavaScript functions to ActionScript, and adapt them according to the API's minor differences.

The result is very impressive: there is both an increased frame rate (from 15-20 fps to 40 fps) *and* a decreased CPU usage. Moreover, the map perfectly follows the vehicle's movement. Quite natural!

The Google Maps API for Flash has enabled us developers to create real-time Google Maps applications. I believe this excellent API has unlimited potential and look forward to using more of it in the future.