Skip to content Skip to sidebar Skip to footer

Embedding Google Maps In Flash

I am working on a flash project that requires me to use google maps. I read an article that says 'Google Maps API for Flash has been officially deprecated as of September 2, 2011'

Solution 1:

I had the same need and also could not find a good ready made solution so I coded and commented a test library below which can serve as the basis for any like project.

Rather than rely on a single provider I implemented the same functionality in Flash across Bing Maps V7, Google Maps V3 and MapQuest Maps V7 JavaScript maps. The code creates lines, dynamic markers and shadows, etc. and also calls their elevation apis. The sample app creates two of each map type in one html page.

To do this you need to have Flash and JavaScript call each other with data and/or closure via registering functions which have names unique to that item.

First each map has a unique mapId and each map MXML component registers a set of external methods with their unique mapId (e.g. fname_mapId) and then creates a Flex-iFrame with a parameterized src HTML for one of the three map types passing mapId, application name, start position etc.

The HTML reads these parameters and gets the SWF object from the parent frame via the application name. It creates a map and registers listeners with the map and adds callbacks to the parent frame using its mapId (e.g. fname_mapId) that allow the creation of markers and lines, each of those with a unique id and again registering functions with the parent frame that now also include the marker-or-line id in their name (e.g. fname_mapId_[lineId|markerId]) that allow setting icons, shadows, line color and their position change or removal.

The HTML also registers functions by mapId to check elevation of a position or a path in general. These call the ajax or routine to request the elevation(s), calling back to the JavaScript and then back to the AS3 registered functions.

-C

Logic in the test actions & callbacks - designed to test all the implemented functionality:

Double click on map:
    Create pin:
        - Settodefault name
        - Add to map
        - Set icon and shadow (note Bing does nottakeshadows; Google can take a marker mask for clicking - not implemented)
        - Callto map for elevation
    Remove previous marker
    Log current markers (should be only 1)
    Create black line from start to pin:
        - Change line color to blue
        - Callto map for path elevation
    Remove previous line
    Log current lines (should be only 1)
Drag marker:
    Start:
        - only logs it was called
    Drag:
        - only logs it was called
    End:
        - Move line tonew lat lng
        - Set line color to orange
        - Sets map tonot accept double clicks
Double click marker:
    - Sets map to accept double clicks again (so after you drag you need todouble click a marker to have map accept double clicks again)
Elevation callback:
    - Changes pin name to include elevation in name
    - Sets new icon and shadow for marker
Elevation path callback - setto300m & 500m - is balloon at 500m on path going to hit? - errorif elevation of path >=500, warn if >=300
    - Sets line color if path max elevation as sampled is:
        Purple:       elevation request error flag set
        Red:          at or above error level
        Red-Yellow:   at or above warning but requested distance not met
        Yellow:       at or above warning level
        Yellow-Green: below warning level but requested distance not met
        Green:        below warning level

The rest of the post with the code was way too long with too many links so I had to put it all here - copy into straight text editor - the code is all very well formatted with spaces: http://pastebin.com/Jzq5E06F

Post a Comment for "Embedding Google Maps In Flash"