Chapter 8. Geolocation API

WHAT'S IN THIS CHAPTER?

  • Working with the Geolocation class

  • Enabling GPS support on Android devices

  • Getting speed and altitude info from the Geolocation class

Where do you want to go today? may have been an old Microsoft advertising campaign, but with access to the GPS location services of Android and iPhone, you can build apps with a slightly different slogan: Go where you want, but we can guide you every step of the way.

AIR for Android and Packager for iPhone provide access to mobile location services through two classes: Geolocation and GeolocationEvent. This chapter shows you how to work with these two classes to make your apps location aware. It highlights four sample apps that utilize geolocation:

  • Geolocate — A simple raw display of location data

  • Poorman Compass — A simple compass app

  • Speedometer — A simple speedometer app

  • FindMeAPizza — An app that finds the nearest pizza shop

GETTING GEOLOCATION DATA

You can use a combination of the Geolocation and GeolocationEvent classes to retrieve geolocation data into your app. The Geolocation class is the controller that dispatches events triggered by the Android location sensor. Table 8-1 displays the properties, methods, and events of Geolocation.

Table 8.1. Geolocation Members

TYPE

NAME

DESCRIPTION

Property

isSupported:Boolean (static)

Indicates whether the device supports geolocation services

Property

muted:Boolean

Specifies whether the user has given permission to access geolocation information in the app

Methods

setRequestedUpdateInterval(interval) ...

Get Professional Flash® Mobile Development: Creating Android™ and iPhone® Applications 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.