It's metadata processor time again! I love the Swiz Framework because it's so powerful, yet simple when you need it to be simple. That being said, it's also got the ability to be easily extended in the form of custom metadata processors. codeviously, I've worked with creating a [Scheduled("5000")] metadata processor, but this time decided to take a mobile twist. AIR for Android gives us some new functionality with relation to reading the GPS unit of the device. There's a new Geolocation class within the AIR API that gives you access to the data coming from the GPS. It can be a bit gnarly to work with and it's not necessarily the easiest thing to understand.
The [Geolocation] metadata processor seeks to simplify this usage as much as possible. To use it, you have to declare it in your Swiz configuration just as you would any other metadata processor:
<fx:Declarations>
<geolocation:GeolocationSetup id="geoSetup" stopOnDeactivate="true" updateInterval="30000"/>
<swiz:Swiz>
<swiz:beanProviders>
<config:Beans/>
</swiz:beanProviders>
<swiz:config>
<swiz:SwizConfig
setUpEventType="{ Event.ADDED_TO_STAGE }"
setUpEventPhase="{ EventPhase.CAPTURING_PHASE }"
setUpEventPriority="50"
tearDownEventType="{ Event.REMOVED_FROM_STAGE }"
tearDownEventPhase="{ EventPhase.CAPTURING_PHASE }"
tearDownEventPriority="50"
eventPackages="org.andypowell.examples.events"
viewPackages="org.andypowell.examples.views"
defaultFaultHandler="genericFaultHandler"
defaultDispatcher="global"/>
</swiz:config>
<swiz:customProcessors>
<processors:GeolocationProcessor config="{geoSetup}"/>
</swiz:customProcessors>
</swiz:Swiz>
</fx:Declarations>
This is pretty straightforward, however, you'll see another tag up there too: GeolocationSetup. This tag allows you to specify the updateInterval, or how long the app will wait until it tries to grab a new reading from the GPS, and the stopOnDeactivate variable. StopOnDeactivate will shutdown the GPS listeners when the application is moved to the background. There is generally not a reason why you'd set this to false since it has the possibility to kill your device's battery by constantly polling the GPS.
Usage of the Geolocation metadata tag is pretty straightforward, as well.
...
[Geolocation]
public function updateLocation(latitude:Number,longitude:Number):void{
...
}
...
The method updateLocation will automatically be called at the updateInterval's next run.
What does this mean for the developer who wants to use this? It means you don't have to mess with setting up listeners with NativeApplication or listeners for Geolocation when it updates the lat/lon. It really simplifies the whole process for you. Head over to my github page and download the metadata processor and examples for yourself. Remember, it requires the Flex 4.5 SDK so make sure you grab that first.























1 response so far ↓
1 Thomas Burleson // Apr 1, 2011 at 7:35 AM
Leave a Comment