I am developing augmented reality android application based on real time location. It is a simple concept: my application should show some places around me. I have researched this intensively and yet I am still running into issues. I have my GPS coordinates and the target place's GPS coordinates.
My question is: How can I retrieve what my phone's camera is looking at (for example a building)? What is the logical way to solve something like this?
First check the availability of sensors in the device. If the device supports TYPE_ROTATION_VECTOR then register a sensor listener for the same or else check for TYPE_MAGNETIC_FIELD and TYPE_ACCELEROMETER.
Then in onSensorChanged function you should calculate the azimuth.
You can use this azimuth to plot the location in cameraview
x, y will give the coordinates of the destination location.
There're two directions in this issue, device and targets.
The Azimuth of device location is shown below:
This information can be collected by sensors. However, if the orientation of the device is not fixed, you should do
SensorManager.remapCoordinateSystem
The azimuth to targets is shown below:
It's probably the best figure I can find on the internet. Once you have device location and the target location can be computed by:
where
tlat
andtlon
indicates target gps locations, lat and lon are device location. the value of this equation lies in -90 to +90, which is not what azimuth really is. So, there're 3 additional code should be added.After these are all done, it's just easy to detect if targets are in your sight.
Hope these helped.
The first step you need is to use sensor to get the direction of the back camera. You can read more about sensor at http://developer.android.com/reference/android/hardware/SensorManager.html
After you are done coding with sensors come back and ask the next question.
Augmented Reality will transfer real coordinates system to camera coordinates system. In AR Location-based, the real coordinate is Geographic coordinate system. We will convert the GPS coordinate (Latitude, Longitude, Altitude) to Navigation coordinate (East, North, Up), then transfer Navigation coordinate to Camera coordinate and display it on camera view.
I just create the demo for you: https://github.com/dat-ng/ar-location-based-android
Try the DroidAR SDK https://github.com/bitstars/droidar . This is a AR SDK for Android. Most of your problems should be solved with it. There are also video manuals. You can also look into the code if you need just some stuff for your project.