Online Book Reader

Home Category

Developing Android Applications with Adobe AIR [50]

By Root 2502 0

import flash.media.CameraRoll;

import flash.media.MediaPromise;

import flash.events.MediaEvent;

import flash.events.Event;

import flash.net.URLRequest

import flash.text.TextField;

import flash.text.TextFormat;

import flash.text.TextFieldAutoSize;

import jp.shichiseki.exif.*;

var cameraRoll:CameraRoll;

var loader:ExifLoader;

if (CameraRoll.supportsBrowseForImage) {

cameraRoll = new CameraRoll();

cameraRoll.addEventListener(MediaEvent.SELECT, onSelect);

cameraRoll.browseForImage();

}

function onSelect(event:MediaEvent):void {

var promise:MediaPromise = event.data as MediaPromise;

loader = new ExifLoader();

loader.addEventListener(Event.COMPLETE, onImageLoaded);

loader.load(new URLRequest(promise.file.url));

}

function onImageLoaded(event:Event):void {

var exif:ExifInfo = loader.exif as ExifInfo;

var textFormat:TextFormat = new TextFormat();

textFormat.size = 40;

textFormat.color = 0x66CC99;

var where:TextField = new TextField();

where.x = 50;

where.y = 200;

where.defaultTextFormat = textFormat;

where.autoSize = TextFieldAutoSize.LEFT;

addChild(where);

if (exif.ifds.gps) {

var gpsIfd:IFD = exif.ifds.gps;

var exifLat:Array = gpsIfd["GPSLatitude"] as Array;

var latitude:Number = shorten(exifLat, gpsIfd["GPSLatitudeRef"]);

var exifLon:Array = gpsIfd["GPSLongitude"] as Array;

var longitude:Number = shorten(exifLon, gpsIfd["GPSLongitudeRef"]);

where.text = latitude + "\n" + longitude;

} else {

where.text = "No geographic \information";

}

}

function shorten(info:Array, reference:String):Number {

var degree:Number = info[0] + (info[1]/60) + (info[2]/3600);

// position from Greenwich and equator

if (reference == "S" || reference == "E") {

degree * -1;

}

return degree;

}

Base 60 is commonly used to store geographic coordinates in degrees. Degrees, minutes, and seconds are stored separately. Put them back together and sign them depending on whether they are south of the equator and east of Greenwich Mean Time.

Displaying latitude and longitude is not very helpful, nor is it interesting for most users. But you can render a static map using latitude and longitude or retrieve an address.

We will come back to these topics in Chapter 10.

Conclusion

Images are among the most popular types of content for mobile applications, whether users are cataloguing the images or manipulating them. You now have all the tools to create one of your own.

Chapter 10. Geolocation

Without geography, you’re nowhere.

—Jimmy Buffett

The ability to locate exactly where you are on Earth via consumer products has become commonplace, yet the technology is empowering. If you own a GPS-capable cellular phone, you have this technology at your fingertips.

In this chapter, we will discuss the geolocation API for accessing location information from an Android device.

Geolocation Classes


The flash.events.GeolocationEvent class is a new Event object that contains updated geolocation information. The new flash.sensors.Geolocation class is a subclass of the EventDispatcher class. It listens for and receives information from the device’s location sensor in the form of a GeolocationEvent.

To use the geolocation classes, first you must add the necessary permissions. In Flash Professional, enable ACCESS_FINE_LOCATION and ACCESS_COARSE_LOCATION device permissions under File→AIR Android Settings→Permissions. In Flash Builder, select ACCESS_NETWORK_STATE and ACCESS_WIFI_STATE under Mobile Settings→Permissions. To make changes, append your application manifest file as follows:

Fine location refers to GPS communication, while coarse location refers to network communication. I will explain the difference between the two later in this chapter.

NOTE

If your location permissions are not set up, your application will fail silently.

During development and testing, you must select the checkboxes on your device in Android Settings→Location

Return Main Page Previous Page Next Page

®Online Book Reader