devxlogo

Augmented Reality on Android: Using GPS and the Accelerometer

Augmented Reality on Android: Using GPS and the Accelerometer

he previous DevX article “Augmented Reality on Android: Prepping the Camera and Compass” explored how to use the Android SDK’s camera and compass as the first two building blocks of an Augmented Reality (AR) engine. This follow-up article details the last two pieces of the puzzle: location and the accelerometer. With the necessary tools in hand, you will learn how to request location updates and find out how the accelerometer works.

What You Need
Android SDK 1.5
T-Mobile G1 phone or equivalent emulator
Eclipse with Android Development Tools (ADT) Plugin, NetBeans, or the IDE of your choice

Talking to the Satellites

The third step along the way to your Augmented Reality Engine on Android?after implementing the first two elements: the camera and the compass?is determining your location. You do this primarily through Android’s LocationManager object. Before you can get one, however, you’ll need to jump through a few hoops. Permissions, while annoying, are an important hurdle you’ll need to clear.

Android’s LocationManager carries two permission requirements:

  1. You need to tell the system you’d like to fetch the user’s location.
  2. You need to tell it that you want very detailed geographic information.

You request both permissions in the AndroidManifest.xml file with the tag inside the tag as follows:

For fine-grain location updates, which you’ll need if the objects you want to display are nearby, you’ll also have to add the following:

Without these two lines in the manifest, when you attempt to register for location updates, Android will return a security exception that will stop your app dead. I don’t believe I’ve written an Android application yet in which I haven’t forgotten at least one permission request.

 

devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist