Adobe
Products

Top destinations

  • Adobe Creative Cloud
  • Creative Suite
  • Adobe Marketing Cloud
  • Acrobat
  • Photoshop
  • SiteCatalyst
  • Students
  • Elements family

Adobe Creative Cloud

  • What is Adobe Creative Cloud?
  • Design
  • Web
  • Photography
  • Video
  • Students
  • Teams
  • Enterprise
  • Educational institutions

Design and photography

  • Photoshop
  • Illustrator
  • InDesign
  • Adobe Muse
  • Lightroom

Video

  • Adobe Premiere
  • After Effects

Web development and HTML5

  • Edge Tools & Services [opens in a new window]
  • Dreamweaver
  • Gaming [opens in a new window]

Adobe Marketing Cloud

  • What is Adobe Marketing Cloud?
  • Digital analytics
  • Social marketing
  • Web experience management
  • Testing and targeting
  • Media optimization

Analytics

  • SiteCatalyst
  • Adobe Discover
  • Insight

Social

  • Adobe Social

Experience Manager

  • CQ
  • Scene7

Target

  • Test&Target
  • Recommendations
  • Search&Promote

Media Optimizer

  • AdLens
  • AudienceManager
  • AudienceResearch

Document services

  • Acrobat
  • EchoSign [opens in a new window]
  • FormsCentral [opens in a new window]
  • SendNow [opens in a new window]
  • Acrobat.com [opens in a new window]

Publishing

  • Digital Publishing Suite

  • See all products
Business solutions

By business need

  • Digital analytics
  • Digital publishing
  • Document management
  • Media optimization
  • Social marketing
  • Testing and targeting
  • Video editing and serving
  • Web development [opens in a new window]
  • Web experience management
  • See all business needs

By industry

  • Broadcast
  • Education
  • Financial services
  • Government
  • Publishing
  • Retail
  • See all industries
Support & Learning

I need help

  • Products
  • Adobe Creative Cloud
  • Adobe Marketing Cloud
  • Forums [opens in a new window]

I want to learn

  • Training and tutorials
  • Certification [opens in a new window]
  • Adobe Developer Connection
  • Adobe Design Center
  • Adobe TV [opens in a new window]
  • Adobe Marketing Center
  • Adobe Labs [opens in a new window]
Download
  • Product trials
  • Adobe Flash Player
  • Adobe Reader
  • Adobe AIR
  • See all downloads
Company
  • Careers at Adobe
  • Investor Relations
  • Newsroom
  • Privacy
  • Corporate Social Responsibility
  • Customer Showcase
  • Contact us
  • More company info
Buy
  • For personal and professional use
  • For students, educators, and staff
  • For small and medium businesses
  • Volume Licensing
  • Special offers
  • Adobe Marketing Cloud sales [opens in a new window]
Search
 
Info Sign in
Why sign in? Sign in to manage your account and access trial downloads, product extensions, community areas, and more.
Welcome,
My Adobe
My orders
My information
My preferences
My products and services
Sign out
My cart
Privacy My Adobe
Adobe
Products Sections Buy   Search  
Solutions Company
Help Learning
Sign in Sign out Privacy My Adobe
Preorder Estimated Availability Date. Your credit card will not be charged until the product is shipped. Estimated availability date is subject to change. Preorder Estimated Availability Date. Your credit card will not be charged until the product is ready to download. Estimated availability date is subject to change.
Qty:
Purchase requires verification of academic eligibility
Subtotal
Promotions
Estimated shipping
Tax
Calculated at checkout
Total
Review and Checkout
Adobe Developer Connection / Gaming /

Using the Adobe AIR Geolocation APIs on Android

by Frank Jennings

Frank Jennings

Content

  • Handling Geolocation events
  • The Geolocation attributes
  • Declaring Android permission
  • Troubleshooting your application
  • Where to go from here

Created

10 October 2011

Page tools

Share on Facebook
Share on Twitter
Share on LinkedIn
Bookmark
Print
Adobe AIRAndroidFlash BuilderFlash Professionalgame developmentgamingmobile
Was this helpful?
Yes   No

By clicking Submit, you accept the Adobe Terms of Use.

 
Thanks for your feedback.

Requirements

Prerequisite knowledge

Familiarity with ActionScript 3.

 

Additional Requirements

  • Adobe AIR 3 SDK

User level

Intermediate

Required products

  • Flash Builder (Download trial)
  • Flash Professional (Download trial)
  • Adobe AIR

Sample files

  • GeLocTest.zip
  • GeLocTest-android.zip

The Geolocation API provides a high-level interface to access the geographical location information of the device. The geographical location can be displayed on the device in the form of latitudinal and longitudinal coordinates. The API is designed to enable both one-shot location request and repeated location updates (useful while building a Geo tracking application). This example shows you how you can get repeated location updates in your application.

In your Android device, when the location of the device changes, your application can receive updates about the changes, including information on altitude, accuracy, heading, speed, and timestamp using one of the following location sources:

  • GPS Satellites: Enables accurate positioning if a GPS sensor is available.
  • Wireless networks: Enables approximate positioning if a data connection is available.

The Geolocation API provides the necessary support to build applications, which uses the location sources configured in the device.

In this article, you will learn about:

  • The Geolocation API
  • Handling Geolocation events in your application
  • Android-related device permissions
  • Troubleshooting your application

Handling Geolocation events

To build Geolocation-based applications, use the following classes:

  • flash.sensors.Geolocation to initilialize location sensor in your device.
  • flash.events.GeolocationEvent to get location information at defined intervals.

To find out if the device supports Geolocation at all, use the Geolocation.isSupported property. This property is false on devices that do not have geolocation capabilities. This property will also return false in an Android emulator, even when you simulate the Geolocation functionality with the Android Emulator's geo fix command, and hence this example will not work in an Android emulator.

The following code initializes your device's location sensor and adds an event listener to get regular location updates from the device:

if (Geolocation.isSupported) { //Initialize the location sensor. geo = new Geolocation(); if(! geo.muted){ geo.setRequestedUpdateInterval(60000); //Register to receive location updates. geo.addEventListener(GeolocationEvent.UPDATE, geolocationUpdateHandler); } }

In the previous example, the time interval for getting location updates is set to 60000 milliseconds (1 minute). You should choose the longest update interval that satisfies your application requirements.

Note: If you do not set the setRequestUpdateInterval property, the device will return the location updates based on the default interval set in the device. To conserve battery power, it is always advisable to provide a longer update interval.

The application can stop performing other activities if the location sources are not available by reading the muted property of the Geolocation class:

if(geo.muted){ //Display an error message or halt the application. }

In the geolocationUpdateHandler function, use the GeolocationEvent's properties to get the location information:

private function geolocationUpdateHandler(event:GeolocationEvent):void { geoLat.text = "Latitude: " + event.latitude.toString(); geoLong.text = "Longitude: " + event.longitude.toString(); geoAccu.text = "Accuracy: " + event.horizontalAccuracy.toString(); geoSpeed.text = "Speed: " + event.speed.toString(); }
Figure 1 illustrates the previously mentioned example.
Getting the location information.
Figure 1. Getting the location information.

The Geolocation attributes

Table 1 shows the Geolocation attributes reported by the GeolocationEvent object.

Table 1. Geolocation properties of the GeolocationEvent object

Attribute Description Unit
latitude The geographical coordinate with a value between –90 to +90 degrees. Negative latitude denotes south and positive latitude denotes north. Degrees
longitude The geographical coordinate with a value between –180 to +180 degrees. Negative longitude denotes west and positive longitude denotes east. Degrees
altitude Vertical height of the geographical coordinates (Latitude and Longitude). Meters
horizontalAccuracy (Accuracy) The horizontal accuracy of the position denoted by the geographical coordinates (Latitude and Longitude). Meters
verticalAccuracy (Altitude Accuracy) The vertical accuracy of the position denoted by the geographical coordinates (Latitude and Longitude). Meters
speed The current ground speed of the device. If the device is stationary, the value of this attribute will be zero. Meters/Seconds
timestamp The time since the application was initialized. For example, if the application has captured geolocation data for four seconds after it got initialized, then the value of this attribute will be 4000. Milliseconds

Note: Although the Heading Geolocation attribute is available through the API, it is not yet supported in the Android devices. The Heading attribute will always return NaN (Not a Number) in an Android application.

Declaring Android permission

For your application to work, you need to specify the necessary Android permission in the application descriptor file under the <android> element.

<android> <manifestAdditions> <![CDATA[<manifest> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> </manifest>]]> </manifestAdditions> </android>

Note that the ACCESS_FINE_LOCATION Android permission is required by the application to use the device's GPS sensor.

Troubleshooting your application

When your application does not return any value for the Geolocation attributes, it could be because of one or more of the following issues:

  • The Geolocation event does not get dispatched. This issue is primarily due to the lack of GPS fix. For a successful GPS fix (GPS device getting connected with four or more satellites), the device should have a clear view of the sky. In an enclosed space, getting a GPS fix in your device is difficult. If you do not need accurate position information in your application, you can use the network-based Geolocation that will rely on the wireless network to get an approximate position of your device. If your application uses the network-based Geolocation, check if your device is configured to send and receive data through a valid Internet APN (Access Point Name). To check if you have configured an Internet APN, go to Settings > Wireless and Networks > Mobile Network > Access Point Names and look for the default entry (the one with a green icon, shown in Figure 2).

Checking the Internet APN configuration.

Figure 2. Checking the Internet APN configuration.

  • GPS is muted. GPS should be enabled if you want to get the position information based on the GPS satellites. In most of the Android phones, the option will be under Settings > Location and Security Settings > My Location sources.

Checking whether GPS is enabled.

Figure 3. Checking whether GPS is enabled.

You can enable both GPS-based and network-based location sources so that if the GPS fix does not happen, your AIR application will try to use the network-based location source (if data connection is available).

  • Android permission issue. You need to specify the ACCESS_FINE_LOCATION Android permission as discussed in the "Declaring Android permission" section above. The ACCESS_FINE_LOCATION permission is required to access GPS location data. Either ACCESS_FINE_LOCATION or ACCESS_COARSE_LOCATION is required to access wireless network location data.
  • Code issue. Check if you have declared the Geolocation object globally in your application. If the Geolocation object is declared locally (inside a method), chances are that the object may get garbage collected. For example, the following code may not work properly because the Geolocation object is declared and initialized inside a method.
public function locateMe() { Geolocation geo = new Geolocation(); ... }
Instead, declare the Geolocation object globally and initialize the object inside the method as shown below:
private var geo:Geolocation; public function locateMe() { geo = new Geolocation(); ... }

If you still face any issue getting the Geolocation API to work in your application, post your issue in the AIR for Android developer forum.

Where to go from here

In this example, you have learned how to use the AIR Geolocation APIs for your Android applications. You can use these Geolocation APIs to build simple-to-complex Android applications involving navigation, speed monitoring, and GPS-based route tracking.

For more information, refer to the following resources:

  • Geolocation API Information

Creative Commons License
This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License

More Like This

  • Using the StageWebView class
  • Capturing video input in a mobile AIR application
  • Capturing soft key input
  • Using the tel: and sms: URIs in a mobile phone application

Products

  • Adobe Creative Cloud
  • Creative Suite
  • Adobe Marketing Cloud
  • Acrobat
  • Photoshop
  • Digital Publishing Suite
  • Elements family
  • SiteCatalyst
  • For education

Download

  • Product trials
  • Adobe Reader
  • Adobe Flash Player
  • Adobe AIR

Support & Learning

  • Product help
  • Forums

Buy

  • For personal and professional use
  • For students, educators, and staff
  • For small and medium businesses
  • Volume Licensing
  • Special offers

Company

  • News room
  • Partner programs
  • Corporate social responsibility
  • Career opportunities
  • Investor Relations
  • Events
  • Legal
  • Security
  • Contact Adobe
Choose your region United States (Change)
Choose your region Close

North America

Europe, Middle East and Africa

Asia Pacific

  • Canada - English
  • Canada - Français
  • Latinoamérica
  • México
  • United States

South America

  • Brasil
  • Africa - English
  • Österreich - Deutsch
  • Belgium - English
  • Belgique - Français
  • België - Nederlands
  • България
  • Hrvatska
  • Česká republika
  • Danmark
  • Eastern Europe - English
  • Eesti
  • Suomi
  • France
  • Deutschland
  • Magyarország
  • Ireland
  • Israel - English
  • ישראל - עברית
  • Italia
  • Latvija
  • Lietuva
  • Luxembourg - Deutsch
  • Luxembourg - English
  • Luxembourg - Français
  • الشرق الأوسط وشمال أفريقيا - اللغة العربية
  • Middle East and North Africa - English
  • Moyen-Orient et Afrique du Nord - Français
  • Nederland
  • Norge
  • Polska
  • Portugal
  • România
  • Россия
  • Srbija
  • Slovensko
  • Slovenija
  • España
  • Sverige
  • Schweiz - Deutsch
  • Suisse - Français
  • Svizzera - Italiano
  • Türkiye
  • Україна
  • United Kingdom
  • Australia
  • 中国
  • 中國香港特別行政區
  • Hong Kong S.A.R. of China
  • India - English
  • 日本
  • 한국
  • New Zealand
  • 台灣

Southeast Asia

  • Includes Indonesia, Malaysia, Philippines, Singapore, Thailand, and Vietnam - English

Copyright © 2013 Adobe Systems Incorporated. All rights reserved.

Terms of Use | Privacy | Cookies

Ad Choices

Reviewed by TRUSTe: site privacy statement