Skip to main content
DJ Gecko
Inspiring
October 16, 2013
Answered

Any Maps the work with AIR for mobile?

  • October 16, 2013
  • 1 reply
  • 2652 views

I'm looking to include a map in my mobile app.

This topic has been closed for replies.
Correct answer BorrelWORST

Hi DJ Gecko,

I'm using Google Maps in as3. Well, actually it's the HTML version of Google Maps, included via flash.media.StageWebView to my app. But it surely looks like it's a native part of the app.

You can see a sample in my app (go to the menu "beleef texel" > select a village > click "plattegrond"/map):

Here's how I've done it:

In actionscript (the bold lines are the most important)

package

{

          import flash.events.Event;

          import flash.events.MouseEvent;

          import flash.display.MovieClip;

          import flash.media.StageWebView;

          import flash.geom.Rectangle;

          import flash.net.*;

          import flash.net.URLRequest;

          import flash.net.URLVariables;

 

          public class boxMapInteractive extends MovieClip

          {

                    public var webView:StageWebView;

                    public var cityAddress:String;

 

                    public function boxMapInteractive(inpCityAddress:String = null):void

                    {

                              addEventListener(Event.ADDED_TO_STAGE, onAddedToStage, false, 0, true);

                              addEventListener(Event.REMOVED_FROM_STAGE, onRemovedFromStage, false, 0, true);

                              cityAddress = inpCityAddress;

                    }

 

                    private function onAddedToStage(e:Event = null):void{

                              showGoogleMap();

                              removeEventListener(Event.ADDED_TO_STAGE, onAddedToStage);

                    }

 

                    private function onRemovedFromStage(e:Event = null):void{

                              hideGoogleMap();

                              removeEventListener(Event.REMOVED_FROM_STAGE, onRemovedFromStage);

                    }

 

                    public function showGoogleMap() {

                              webView = new StageWebView();

                              webView.stage = this.stage;

                              webView.viewPort = new Rectangle(0,0,500,500); // x, y, width, height

                              webView.loadURL("http://www.yoursite.com/googlemaps.php?location=Rijksmuseum,Amsterdam");

                    }

 

                    public function hideGoogleMap() {

                              stage.removeChild(btnOpenDirections);

                              webView.stage = null;

                              webView.dispose();

                    }

          }

}

In googlemaps.PHP


<!DOCTYPE html>

<html>

  <head>

    <title>Google maps</title>

    <meta name="viewport" content="initial-scale=1.0, user-scalable=no">

    <meta charset="utf-8">

    <style>

      html, body, #map-canvas {

        margin: 0;

        padding: 0;

        height: 100%;

      }

    </style>

    <script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false"></script>

    <script>

     var map;

     geocoder = new google.maps.Geocoder();

     function initialize() {

      var mapOptions = {

         zoom: 15,

         mapTypeId: google.maps.MapTypeId.ROADMAP

      };

      map = new google.maps.Map(document.getElementById('map-canvas'),

          mapOptions);

         

         codeAddress();

     }

     function codeAddress() {

     var address = '<?= $_GET['location'] ?>';

     geocoder.geocode( { 'address': address}, function(results, status) {

      if (status == google.maps.GeocoderStatus.OK) {

         map.setCenter(results[0].geometry.location);

         var marker = new google.maps.Marker({

               map: map,

               position: results[0].geometry.location

         });

      } else {

         alert("Error loading map");

      }

     });

     }

     google.maps.event.addDomListener(window, 'load', initialize);

    </script>

  </head>

  <body>

    <div id="map-canvas"></div>

  </body>

</html>

And that should pretty much do the trick!


1 reply

BorrelWORSTCorrect answer
Participant
October 17, 2013

Hi DJ Gecko,

I'm using Google Maps in as3. Well, actually it's the HTML version of Google Maps, included via flash.media.StageWebView to my app. But it surely looks like it's a native part of the app.

You can see a sample in my app (go to the menu "beleef texel" > select a village > click "plattegrond"/map):

Here's how I've done it:

In actionscript (the bold lines are the most important)

package

{

          import flash.events.Event;

          import flash.events.MouseEvent;

          import flash.display.MovieClip;

          import flash.media.StageWebView;

          import flash.geom.Rectangle;

          import flash.net.*;

          import flash.net.URLRequest;

          import flash.net.URLVariables;

 

          public class boxMapInteractive extends MovieClip

          {

                    public var webView:StageWebView;

                    public var cityAddress:String;

 

                    public function boxMapInteractive(inpCityAddress:String = null):void

                    {

                              addEventListener(Event.ADDED_TO_STAGE, onAddedToStage, false, 0, true);

                              addEventListener(Event.REMOVED_FROM_STAGE, onRemovedFromStage, false, 0, true);

                              cityAddress = inpCityAddress;

                    }

 

                    private function onAddedToStage(e:Event = null):void{

                              showGoogleMap();

                              removeEventListener(Event.ADDED_TO_STAGE, onAddedToStage);

                    }

 

                    private function onRemovedFromStage(e:Event = null):void{

                              hideGoogleMap();

                              removeEventListener(Event.REMOVED_FROM_STAGE, onRemovedFromStage);

                    }

 

                    public function showGoogleMap() {

                              webView = new StageWebView();

                              webView.stage = this.stage;

                              webView.viewPort = new Rectangle(0,0,500,500); // x, y, width, height

                              webView.loadURL("http://www.yoursite.com/googlemaps.php?location=Rijksmuseum,Amsterdam");

                    }

 

                    public function hideGoogleMap() {

                              stage.removeChild(btnOpenDirections);

                              webView.stage = null;

                              webView.dispose();

                    }

          }

}

In googlemaps.PHP


<!DOCTYPE html>

<html>

  <head>

    <title>Google maps</title>

    <meta name="viewport" content="initial-scale=1.0, user-scalable=no">

    <meta charset="utf-8">

    <style>

      html, body, #map-canvas {

        margin: 0;

        padding: 0;

        height: 100%;

      }

    </style>

    <script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false"></script>

    <script>

     var map;

     geocoder = new google.maps.Geocoder();

     function initialize() {

      var mapOptions = {

         zoom: 15,

         mapTypeId: google.maps.MapTypeId.ROADMAP

      };

      map = new google.maps.Map(document.getElementById('map-canvas'),

          mapOptions);

         

         codeAddress();

     }

     function codeAddress() {

     var address = '<?= $_GET['location'] ?>';

     geocoder.geocode( { 'address': address}, function(results, status) {

      if (status == google.maps.GeocoderStatus.OK) {

         map.setCenter(results[0].geometry.location);

         var marker = new google.maps.Marker({

               map: map,

               position: results[0].geometry.location

         });

      } else {

         alert("Error loading map");

      }

     });

     }

     google.maps.event.addDomListener(window, 'load', initialize);

    </script>

  </head>

  <body>

    <div id="map-canvas"></div>

  </body>

</html>

And that should pretty much do the trick!


DJ Gecko
DJ GeckoAuthor
Inspiring
November 28, 2013

nice. Thanks!