Watch videos with subtitles in your language, upload your videos, create your own subtitles! Click here to learn more on "how to Dotsub"

GEO Location API for Adobe AIR on Android

0 (0 Likes / 0 Dislikes)
[ringing sound] [ADOBE DEVELOPER CONNECTION] Hi, I'm Ryan Stewart. [Ryan Stewart - Platform Evangelist] I'm a platform evangelist with Adobe Systems. Today I'm going to show you how to use the GEO Location API that's part of Adobe AIR for Android. AIR for Android is currently in private beta, but you can go and sign up on Adobe Labs and get access to the private beta. So I've got an application here that I've already created called Where Am I? I'm going to go through and show just a basic use of the GEO Location API. Let me start by creating a Creation Complete Handler on the application. So when the application starts, the first thing we have to do is make sure that the device that we're on supports GEO Location. We do that by just saying [if Geolocation.isSupported)] and then if we have access to it, we can start creating the application and then accessing that GEO Location data. So now that it's supported, let's go ahead and create a variable that's going to be our GEO Location instance. [public var geo.GeoLocation;] Var, geo. Just type GeoLocation. And then within the script block I can say [geo = new Geolocation();] and we're good to go. There is one property and a couple of different events that you have to listen to when you're dealing with GEO Location data. The property is a property that allows us to set the interval for how often we'll ping the device and get GEO Location data from it. So I can set [geo.setRequestedUpdateInterval(100);] It's in milliseconds, so I'll just give it an interval of 100. And then I also have to set two different events that are kind of valuable when I'm dealing with GEO Location data. The first one is the Status Event, which will tell us whether the GEO Location is working or the GPS device is on. So I can say [geo.addEventListener(StatusEvent.STATUS] and then I'll create an event listener and go back to that a little bit later on. The second one is the most important one, and that's the one that actually pings the device and deals with the data that we get back from it and how we're going to handle that. So we can set that by doing [geo.addEventListener] [geo.addEventListener(GeolocationEvent.UPDATE] and then creating an event listener for that as well. So down here on my Status Event that I created, I'm going to go ahead and trace this out or put text out to my textarea box to show me when the GEO Location device is on or when the status changes. So if we go down to the Status Event, I'm just going to trace this out to the text area, so I'll do ta.text, and we'll set that to event.code, and that'll give us access to what's happening with the GPS device when we access it or when we try to access it. So the second one--the most important one--is this On Update function. This is where we actually ping the device and deal with the data that comes back. So here if I type the event and look at a list of properties, you can see that I've got altitude, I've got heading, accuracy, and typical longitude and latitude. This is where the data comes in, so every time it calls the device, which I set based on that Set Requested Update Interval, it's going to call this function and give me that information. So I'm going to go ahead and do ta.text and just trace this out to the text area as well. [= event.latitude.toString], and then I'll concatenate that, do a comma, and do [event.longitude.toString], and then I'll just add an extra space so we can do a line end character. All right. Perfect. The last thing you have to do--this is really all the code it takes when you're dealing with GEO Location is just the Status Event, the GEO Location Event, and that Update Interval function or property. Now the only thing we have to do is go into the application.xml file and change some things in there. If you're an AIR developer, you're familiar with the application.xml file. It's got a lot of properties that the AIR application uses to define things like the ID or the name. And for AIR for Android, we have a separate Android Manifest file with some Android-specific properties. One of the things that these Android-specific properties do are give us access to the specific types of information from the device. So we have Internet, we have Rate External Storage, we have Access Find Location, which is the one that we want so that we actually get permission from the user to use whatever API that we're calling. So I just need to uncomment these really quickly. So uncomment the Android Manifest portion [keys clicking], and that's going to let us use these APIs inside of our application. And you can see that the application.xml file from the SDK comes with a lot of information and a lot of stub code, so you can uncomment and comment things out as needed and delete the ones that you're not worried about. [keys clicking] All right. So I'll save that and make sure that there's no errors in my app.xml file. And now I'm ready to send this to the device and make sure to test it. One of the things about using the GEO Location API is you can't really test it on your machine, so you've got to test it on the device, which has an actual GEO Location support on it, and you can use the GPS directly on the device. So let me go ahead into my terminal and go into the application, Where Am I? There we go. [keys clicking] And in the Bin Debug folder it's going to create the app.xml file as well as the SWF file, and so I use ADT just like you would use it if you were building a regular AIR application, but I'm going to package this one for Android specifically. So I'll do package and I'll use the [ -target.apk] and then I have to give it a keystore, so I still need to use my certificate in all the typical functions that I would use for any AIR application. So storetype is pkcs12. Keystore points to my certificate. And then I can do WhereAmI.apk, the WhereAmI-app.xml file, and then the SWF file that I want to package, and that should run. It'll prompt me for my certificate password, and then it should go ahead and package that up into an APK file, which is the native format for Android, so I can then deploy that native file to the device. Make sure we have it. There's my APK file. I can use the Android SDK now to push this to the device and test it directly on there. So Library SDKs. [keys clicking] So use ADB to do that, so I can do [- install - r] and I just point this at the APK file. And then my device is plugged in via USB, so it's going to send my application to the device. I can come over here to the Nexus One and scroll down to Where Am I? open it up, and our text area should load, and it should tell us that GEO Location is supported or give us the status. And then you see, okay, we're getting longitude and latitude. So you see the little GPS signal went on, and we have longitude and latitude. So we could plug into a map and you could see that I am deep in the bowels of Adobe San Francisco, filming a video. For more information on AIR for Android, you can go to labs.adobe.com and you can sign up for the private prerelease. [For more information labs.adobe.com] We're accepting anyone who wants to sign up right now, and it'll give you access to the SDK, documentation, and then you can make use of this yourself and test it on your own AIR for Android device. [ADOBE DEVELOPER CONNECTION]

Video Details

Duration: 7 minutes and 43 seconds
Country:
Language: English
License: All rights reserved
Genre: None
Views: 220
Posted by: adobetv on Oct 21, 2010

Platform Evangelist Ryan Stewart examines the capabilities of a GeoLocation application, enabled by Adobe AIR, on an Android device.

Caption and Translate

    Sign In/Register for Dotsub to translate this video.