Chapter 10. Geolocation
Without geography, you’re nowhere.
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:
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
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 ...
Get Developing Android Applications with Adobe AIR now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.