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.
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.
Reply
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.
Reply
Show the rest of this thread