Do you have an Android device (or an iOS device or a Blackberry Playbook)?  Do you have Adobe Flash Builder 4.5 (with 4.5.1 sdk)?  Do you have access to ArcGIS Server map services (the answer is yes)?

Then take a look below for the quick and dirty on creating an Air app that tracks your location with an ArcGIS Server map service.

First make sure you have Flash Builder with 4.5.1 sdk fired up.

Start a new “Flex Mobile Project”.  Give it a name. Click “Next”.  Choose the “Blank” template.  Click the “permissions” tab, choose “Google Android” and check “ACCESS_FINE_LOCATION”.  Click “Next”.  Click “Next”.  Add the AGS Flex 2.3.1 swc.  Also, you’ll need to add* the mx.swc and sparkskins.swc libraries located at “C:\Program Files\Adobe\Adobe Flash Builder 4.5\sdks\4.5.1\frameworks\libs\”.  Click “Finish”.

*The addition of mx.swc and sparkskins.swc will not be needed with the next release of the AGS Flex API.

Open your project default application, delete the existing code and add the following code:

<?xml version=”1.0″ encoding=”utf-8″?>
<s:Application
xmlns:fx=”http://ns.adobe.com/mxml/2009&#8243;
xmlns:s=”library://ns.adobe.com/flex/spark”
xmlns:esri=”http://www.esri.com/2008/ags&#8221; >
 
<fx:Script>
<![CDATA[
import com.esri.ags.Graphic;
import com.esri.ags.geometry.MapPoint;
import com.esri.ags.geometry.WebMercatorMapPoint;
import flash.sensors.Geolocation;
import mx.events.FlexEvent;
 
private var _geoLocation:Geolocation;
 
protected function map1_creationCompleteHandler(event:FlexEvent):void
{
if (Geolocation.isSupported)
{
_geoLocation = new Geolocation;
_geoLocation.setRequestedUpdateInterval(3000);
_geoLocation.addEventListener(GeolocationEvent.UPDATE, handleLocationRequest);
}
}
 
private function handleLocationRequest(e:GeolocationEvent):void
{
var mp:MapPoint = new WebMercatorMapPoint(e.longitude, e.latitude);
var g:Graphic = new Graphic(mp);
trackingLayer.clear();
trackingLayer.add(g);
map.scale = 36111;
map.centerAt(mp);
}
]]>
</fx:Script>

<esri:Map id=”map” x=”0″ y=”0″ width=”100%” height=”100%” creationComplete=”map1_creationCompleteHandler(event)”>
<esri:ArcGISTiledMapServiceLayer url=”http://services.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer”/&gt;
<esri:GraphicsLayer id=”trackingLayer”/>
</esri:Map>
</s:Application>

Plug your android device into your computer via USB and run the app.  Enjoy.

The idea here is pretty simple.  Add a map, a map layer and a graphics layer.  Add a geoLocation object that updates every 3 seconds and fires off an update event.  Get the coordinates from the event, convert them to webMercator and feed those results into a graphic.  Add the graphic to the map,   zoom to and center on that graphic.

Now for a little philosophy.  Many out there rag on Flash and rightly so, but let’s put something in perspective:  The app code above works in desktop browsers (although the geolocation object won’t work), Android devices, iOS devices and the Blackberry Playbook.  Code once, deploy many.  The price to be paid is having to keep Adobe Air loaded on our devices.  Is this a fair price to pay?  For now, I think so.