Packaging UMap API for IPhone

Last week I finally had a chance to test UMap ( ActionScript 3.0 mapping API ) on IPhone. Aside from running into some minor issues with provisioning files, the entire process of packaging a Flash application for IPhone [in Flash CS5] went smoothly.

To my surprise I didn’t have to make any changes to UMap nor to my test application, the whole thing worked from the very first try. I was able to load KML files from UMapper, switch between map data providers (Bing, Yahoo, Google, OpenStreetMap), access IPhone’s GPS coordinates and use accelerometer. Here is a quick video demo – apologizies for the poor quality.

And here is the code that makes this work:

package  {
 
	import flash.display.MovieClip;
	import flash.events.Event;
	import flash.events.GeolocationEvent;
	import flash.sensors.Geolocation;
	import flash.display.Sprite;
 
	import com.afcomponents.umap.events.MapEvent;
	import com.afcomponents.umap.core.UMap;
	import com.afcomponents.umap.overlays.FeedLayer;
	import com.afcomponents.umap.overlays.Marker;
	import com.afcomponents.umap.types.LatLng;
	import flash.events.MouseEvent;
 
	public class IphoneMap extends MovieClip {
 
		private var _map:UMap;
		private var _feed:FeedLayer;
		private var _location:Geolocation;
		private var _count:Number=0;
 
		public function IphoneMap() 
		{
			createChildren();	
		}
 
		private function createChildren():void
		{
			_map = new UMap();
			_map.setSize(stage.stageWidth, stage.stageHeight-49);
			_map.doubleClickMode = "zoom";
 
			var tab_bg = new Sprite();
			tab_bg.graphics.beginFill(0x000000);
			tab_bg.graphics.drawRect(0,0,stage.stageWidth, 49);
			tab_bg.x = 0;
			tab_bg.y = stage.stageHeight-49;
 
			var map_btn:MapButton = new MapButton ();
			map_btn.x = 20;
			map_btn.y = tab_bg.y+ 10;
			map_btn.addEventListener(MouseEvent.CLICK, loadData);
 
			var target_btn:TargetButton = new TargetButton();
			target_btn.x = stage.stageWidth -( 20+target_btn.width);
			target_btn.y = tab_bg.y+10;
			target_btn.addEventListener(MouseEvent.CLICK, initLocation);
 
			this.addChild(tab_bg);
			this.addChild(target_btn);
			this.addChild(map_btn);
 
			this.addChild(_map);
		}
 
		function loadData(event:MouseEvent):void
		{
			_feed = new FeedLayer();
			_feed.autoShow = true;
			_map.addOverlay(_feed);
 
			var ids = ["57828","57823","57830"];
 
			_feed.load("http://umapper.s3.amazonaws.com/maps/kml/"+ids[_count]+".kml");
 
			if(_count==2){_count = 0;}else{_count ++;}
		}
 
		function initLocation(event:MouseEvent):void
		{
			_location = new Geolocation();
			_location.setRequestedUpdateInterval(5000);
			_location.addEventListener(GeolocationEvent.UPDATE, onLocationReceived);
		}
 
		function onLocationReceived(event:GeolocationEvent):void
		{
			_map.setCenter( new LatLng(event.latitude, event.longitude), 5);
 
		}
	}
}

Leave a Reply