logo

Using Multiple Google Maps Keys With Flex

Although I really like Google Maps I've always found the need to use a per-domain key a bit of a bind. If, say, you have a site that's accessible via "www.mysite.com" and "mysite.com" while you develop and test at "mysite.local" then you need to store three different keys and add the code to manage these at "run time".

It seems they've done away with the need for keys in Version 3 of Google Maps, but that's still in beta and there's no Flash/Flex version available yet, so we're stuck with version 2 and the need for keys.

To manage multiple keys in Flex I add two global variable, like so:

private var mapsKeys:Object ={
        'www.jakehowlett.com':'ABQIAAAA.. ..R_BRL55wf4H9siydaLHHktow8PWLQvQ',
        'jakehowlett.com':'ABQIAAAA.. ..Tasst5HHy_Bty7uIkasd4rtW23fggf',
        'jakehowlett.local':'ABQIAAAA.. ..4jBTDQNoR7luYGeXHMFr5rVxi2XcSjA'
};

[Bindable]                      
public var mapKey:String;

The first object stores each key I might need. The second variable gets assigned the right key once the app has loaded, by using an "init" event:

protected function init(event:FlexEvent):void{
 if (loaderInfo){ //make sure init is called from applicationComplete method!
  var url:String = loaderInfo.url;
  var bits:Array = url.split("//");
  mapKey = mapsKeys[String(bits[1].substring(0, bits[1].toString().indexOf("/")))];
 }
}

Then in the MXML I add the Google Maps component and bind its key property to this variable we set.

<maps:Map id="map" width="100%" height="400" key="{mapKey}"></maps:Map>

Et voila! Simple. Not.

Comments

  1. I think it's cool that you're using Google Maps... and cool a second time that you're using it Flex. Tell me it ties into Domino data at some point and I'll fall over.

      • avatar
      • Jake Howlett
      • Mon 24 May 2010 07:26 AM

      Wish I could, but I've only done with ASP.NET so far. Of course, there's no reason at all it can tie in to Domino.

      Show the rest of this thread

Your Comments

Name:
E-mail:
(optional)
Website:
(optional)
Comment:


About This Page

Written by Jake Howlett on Mon 24 May 2010

Share This Page

# ( ) '

Comments

The most recent comments added:

Skip to the comments or add your own.

You can subscribe to an individual RSS feed of comments on this entry.

Let's Get Social


About This Website

CodeStore is all about web development. Concentrating on Lotus Domino, ASP.NET, Flex, SharePoint and all things internet.

Your host is Jake Howlett who runs his own web development company called Rockall Design and is always on the lookout for new and interesting work to do.

You can find me on Twitter and on Linked In.

Read more about this site »

More Content