Google Maps in (a) Flash!

Yesterday, we posted a new part to Rolex.com: the ability to find a local Authorised Rolex Dealer. This on its own is hardly breaking any new ground — it’s a fairly routine piece of functionality. To help you find your local dealer, we provided a map — a Google Map.

Google Maps Flash Interface

Those of you who know the two technologies are probably now scratching your heads. Google Maps. Flash. Aren’t they incompatible?

Not any more.

Flash is wonderful. I love it and have loved it for years. But Flash on its own has its limitations, especially when we look at the bigger picture of digital marketing. What Flash really brings to the table is experience: a merging of sound, animation, video, and data that creates something you can’t easily do in DHTML. It’s limitations are also well-known: no SEO support, no deeplinking, the browser’s back button doesn’t see what you’re doing, and bookmarking has limited effect. And Google Maps isn’t supported in Flash — it’s an AJAX application.

Most of those other issues we’d already conquered with Rolex.com. When we came to helping you find a dealer, we needed a solution that provided the best global solution, and Google Maps had the best map coverage. It was the lack of Flash support that was a problem.

But we don’t shy away from problems. We love a good challenge!

While our web developers sat down to use the default Google Maps API, we in the Flash team had a problem: how to use the API? Google has developed a powerful tool that covers a lot of ground (no pun intended), but it’s geared to using JavaScript. While JavaScript and ActionScript have a common ancestor, they don’t really cohabitate. Initial prototypes revealed that passing requests back to JavaScript to make a request, then trying to read the returned data were not just ineffective, they were nigh on torture.

We came across one other example, but it required you to use their server to request images (assumedly to support the API key). Dependence on someone else’s system wasn’t an option. We needed a portable solution, so that we could run it on any of our projects. We went back to our mantra: if it’s worth doing, it’s worth doing right. And that meant figuring out just how Google Maps actually works. I have to say — Google has an absolutely elegant and simple solution. Translating them into Flash was a bit tricky:

  1. Zoom levels and the map tiles are related. (Think of a search tree, where each deeper level accesses more detailed tiles.)
  2. Mercator projection isn’t just something you heard about in 6th grade geography. (While a specific point might dead-accurate up-close, it can shift hundreds of kilometres at the world zoom level.)
  3. The Google API uses an API key to validate usage. And you need to use it for almost every request.
  4. Reverse engineering in this case does not eliminate the contractual obligations.
  5. It’s actually best to use a different map tile loading pattern than the Maps API. (Flash does a better job of loading than AJAX.)

Still with me? (Admittedly, I’m aiming for a slightly different audience with this post than with our other ones.) In the end, we had to effectively develop a Flash interface for Google Maps. It reproduces the core functionality, and allows you to skin it however you need. It integrates correctly with the Maps servers, requiring the API key to work. But it’s light (30k, compiled), fast, customisable…

…and freely available to you.

Thanks very kindly to Rolex, we are releasing the source code for the Google Maps Flash interface to the world. It’s our way of paying back into the open source community that provided some of the code that we used to build Rolex.com. Sadly, the interface is not complete — we only developed what we needed, and did not reproduce the entire API. That said, if you feel the urge to add to the code, we would certainly welcome contributions.

You can find the project (conveniently enough) at Google Code: http://code.google.com/p/google-maps-flash-interface/

Some notes anyone wanting to use this code should be aware of:

  • You need an API key to use this — they’re free, so that shouldn’t slow you down
  • This code supports only ActionScript 2 (we’ll have an ActionScript 3 version sometime in 2008)
  • This is released under the BSD License (in other words, you’re free to do with it as you please, but there’s no direct support)

Happy mapping!

21 Responses to “Google Maps in (a) Flash!”


  1. 1 Quentin

    Man, that’s a huge work!
    Very nice execution…

  2. 2 Geoff Sowrey

    Thanks, Quentin! It’s not the bees knees yet, but we should get there soon.

  3. 3 Andrés Santos Adobe Flex

    Wow 30kb is nothing, but as you said it is great to have something light and powerful, I will certainly try what you guys have done with the gmaps :-D
    grettings!

  4. 4 Geoff Sowrey

    We hope you like it and find it useful! Naturally, if you have any ideas, suggestions, or issues, please let us know! (Google Code is the best place for that information, so it benefits others.)

  5. 5 Jeremy Tooley

    Man.. this rocks guys…

    Always awesome to see great flash developers in Calgary. This is phenomenal!! Where did you find the time at Cmass…. hahaha!!

    Jeremy

  6. 6 chris

    Why not just use AS3 Modest Maps API? it works great with several different map providers.. including google.

  7. 7 Scott Ingalls

    Thanks Jeremy,

    It took me a couple of months to figure out how Google was using Mercator’s Projection to draw the maps, but once I got that it was all a matter of hooking up the proper calculations. To respond to Chris, the Rolex site is AS2, not AS3.

  8. 8 Tom Döhler

    Hi,

    thanks for the great work! Looking at the source code, I can’t find anything that seems to be related to the API-Key though … where do I reference my API-Key?

  9. 9 Raj

    This is exactly what I was looking for!
    Thanks:)

  10. 10 arun

    Are you coming up with AS3 version of this one? if so, any rough dates that you would like to reveal?

    Yahoo maps on the other hand for AS3 uses an externalInterface… cuts me down…

  11. 11 Bruce Hazelton

    Excellent work!

    Clearly you’ve developed this some more, comparing the code on Google to the Rolex execution, will you be posting updated code?

    If not, can you shed any light on why the map is so dark? I notice the Rolex version is fine…

    Thanks
    Bruce

  12. 12 Los Angeles Motorcycle Accident Attorney

    I loaded the API key, but can’t figure out how to make it go to my address. Anyone can help? Here it is now. http://www.ehlinelaw.com/maps.html

  13. 13 Till

    I have the same problem as Tom Döhler.
    Where do I reference my API-Key?

  14. 14 MArcio

    Na minha aplicação aparece o seguinte erro

    SecurityError: Error #2070: Security sandbox violation: caller http://maps.googleapis.com/maps/lib/map_1_3.swf cannot access Stage owned by http://www.rarusflats.com.br

    Lembrando que ja tenho o crossdomain na base do site

    http://www.rarusflats.com.br/crossdomain.xml

    Pode me ajudar a resolver isso ?

  1. 1 Google Maps in (a) Flash! at Sowrey.org
  2. 2 Critical Mass releases Google Maps Flash API
  3. 3 Apukeittiö.fi » Blog Archive » Karttoja Flashiin
  4. 4 Diseñadora Web Multimedia » Blog Archive » Acceder a Google Maps desde Flash
  5. 5 Our Techno Lyrics » Blog Archive » Links for 2008-01-17 [del.icio.us]
  6. 6 links for 2008-01-18 -- A Tempest of Thoughts
  7. 7 Experience Matters Turns 100. What Have We Learned? at Experience Matters

Leave a Reply






buy viagra online generic viagra cheap viagra viagra online viagra prescription herbal viagra natural viagra order viagra viagra for sale discount viagra viagra sale viagra without prescription buy cheap viagra buy generic viagra order viagra online cheapest viagra prices cheap generic viagra viagra pills viagra pills try viagra for free viagra canada viagra 6 free samples side effects of viagra purchase viagra online uk viagra sales viagra dosage viagra pill buying viagra online over the counter viagra viagra on line cialis vs viagra viagra cheap online viagra viagra sample buy viagra cheap viagra soft tabs what is generic viagra viagra no prescription viagra samples buy viagra meds online viagra over the counter viagra alternatives non prescription viagra canadian viagra viagra stories viagra lawyers viagra mexico low cost viagra viagra uterine thickness viagra prices viagra from india buy cheap viagra online uk