Reading Google Maps API in Flash AS3

Tutorials No Comments

The use of google maps in flash AS3 is simple and straightforward. First go to Google Maps API for Flash and download the zip file. Now extract the files and copy flash component file under lib directory to where you have flash installed (under component dir). Usually path is:  C:Program FilesAdobeAdobe Flash CS4languageCommonConfigurationComponents. Now open your Flash and go to components (window/components). You will see GoogleMapsLibrary under Google Maps API (lib). Drag it to your library on stage. In next step we will import neccessary classes that will take care of our Google Maps Application:


import com.google.maps.*;
import com.google.maps.overlays.*;
import com.google.maps.controls.*;

Next step is definition of variables needed for google maps creation:


var map:Map = new Map();
map.key =
“ABQIAAAAqHHCopGV2FznT8V5ph6ELxShFIAhFb89IoGWiehHpBPf2E8vHxQ2wvPhcSdLLuc6JxXYONuPAmqLRA”;
map.setSize(new Point(stage.stageWidth, stage.stageHeight));
map.sensor = “true”;
map.x = 0;
map.y = 0;
map.addEventListener(MapEvent.MAP_READY, onMapReady);

function onMapReady(e:Event):void
{
map.addControl(new ZoomControl());
map.addControl(new MapTypeControl());
map.setCenter(new LatLng(37.77114, -122.40159), 18, MapType.SATELLITE_MAP_TYPE);
var m:Marker = new Marker(new LatLng(37.77114, -122.40159));
map.addOverlay(m);

}

All we have to do now is add google map to the stage:

this.addChild(map);

google maps flash AS3

Save and export movie and map with marker on Adobe location should appear. You can now opearate with it just like on Google pages. Scroll in and out, move accross the map, switch among views and more.

Our next move should be getting desired coordinates of our locations. You probably would like to show location of your company or your home and set it as default map location. Getting coordinates is actually pretty simple.

Go to Google Maps and find the desired location. Now use right click and then select “center map here”. Now paste following code into browser URL:

javascript:void(prompt(”,gApplication.getMap().getCenter()));

A pop up window with coordinates will appear. Just copy this coordinates and paste them to flash code:


map.setCenter(new LatLng(37.77114, -122.40159), 18, MapType.SATELLITE_MAP_TYPE);
var m:Marker = new Marker(new LatLng(37.77114, -122.40159));

Coordinates for marker define exactly where marker of your location is placed.
And we’re done. Thank you for reading Google Maps API in Flash AS3 tutorial. Good luck using it in your projects and don’t forget to download source file.

[download id=”16″]

Za dobre recenzije knjig pa si preberite več na strani listanje. Našli boste vse od mladinske literature do najbolj branih knjig za odrasle.

We really appreciate you for visiting PremiumCoding and reading this article! Now you might also want to check out our Themes here.