Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I am planning to buy a GPS enabled android phone and develop an Augmented Reality application (which will point the locations in front of camera).

All i found about GPS is that it just tells the location of the device, how do i get the direction where camera is pointing, and height of device? how to make compass (2D, 3D) with GPS enabled phone?

Is responsibility of phone to tell the direction?

(please correct, if i asked this question at wrong place)

share|improve this question
    
You probably should take a look at some existing AR apps and the gps/compass samples etc before embarking on this kind of project, research first then come back with specific questions... –  Thomas James Apr 27 '11 at 10:31

2 Answers 2

up vote 2 down vote accepted

GPS by itself cannot tell you the direction. Most phones will also include a digital compass which can give you information about heading (north, south, east, west) and an accelerometer which can tell you information about angle (i.e. whether the phone is at 45o or horizontal, etc).

For Android in particular, you'll want to look at the SensorManager class, which has a list of all the sensors that the phone has attached. SensorManager.getRotationMatrix() packages all the data from the sensors into an easy-to-use rotation matrix for your application.

share|improve this answer
    
My phone will have GPS, proximity sensor and accelerometer. It means i can get all information i want with that package. But it is not possible with just GPS as it only gives the 2D coordinates ?? –  LifeH2O Apr 27 '11 at 6:58
    
@LifeH2O: correct, GPS only gives you latitude and longitude. You would also need a digital compass to get your phone's heading (north, south, east, west) - an accelerometer cannot tell you that and a proximity senor is only used to tell whether the phone is next to your ear or not... –  Dean Harding Apr 27 '11 at 8:46
    
GPS will also give you altitude, but it is not accurate at all ... not to mention that GPS accuracy is pretty low to begin with. –  Thomas James Apr 27 '11 at 10:33
    
@dean-harding Ok, I understood, Accelerometer + Digital Compass = 3D compass and adding GPS I can make an Augmented Reality navigation application. Thanks :) –  LifeH2O Apr 27 '11 at 12:51
    
The compass is the right answer for the OP's purpose, but for others that might find this later: GPS can be used to give you a vector IF YOU ARE MOVING (draw a line between last two sample points) many of them implemented this in the firmware on older phones. I cannot speak for android, but in many of the older HTC devices it was more accurate to use the accelerometer for phone orientation and the GPS for direction if you were moving more than 10mph or so. –  Bill Apr 27 '11 at 18:36

Well, it looks like the direction is available as part of the Android API - GeomagneticField...

As a side note, looking at that really made me want to do some Android stuff :)

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.