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.

 

Share the Post:
Share on facebook
Share on twitter
Share on linkedin

Overview

The Latest

Top 5 B2B SaaS Marketing Agencies for 2023

In recent years, the software-as-a-service (SaaS) sector has experienced exponential growth as more and more companies choose cloud-based solutions. Any SaaS company hoping to stay ahead of the curve in this quickly changing industry needs to invest in effective marketing. So selecting the best marketing agency can mean the difference

technology leadership

Why the World Needs More Technology Leadership

As a fact, technology has touched every single aspect of our lives. And there are some technology giants in today’s world which have been frequently opined to have a strong influence on recent overall technological influence. Moreover, those tech giants have popular technology leaders leading the companies toward achieving greatness.

iOS app development

The Future of iOS App Development: Trends to Watch

When it launched in 2008, the Apple App Store only had 500 apps available. By the first quarter of 2022, the store had about 2.18 million iOS-exclusive apps. Average monthly app releases for the platform reached 34,000 in the first half of 2022, indicating rapid growth in iOS app development.