问题
Guyz,
I need to show the locations(ex restaurants, theaters, banks etc) on the camera preview when I move the camera around me. I know how to get the locations (ex from foursquare or Google maps) and I also know how to open the camera preview. I just don't know how to link these two. I googled it, but did not get a helpful post maybe because my english is not good.
So guys I need your help, if you know any post regarding this issue please be kind enough to comment it.
Thanks in advance.
EDIT: Real Time Camera Preview
------------------------------------------------------------------------------
| Theater |
| |
| Bank |
| Restaurant |
| |
| |
| |
| |
| |
------------------------------------------------------------------------------
Pardon me I am less than 10 reputations, so can not upload images.
Hope this will help to understand my question.
回答1:
I did a similar thing on Android, too. Let's assume that what you want to print on preview is called target.
You definitely know what's the coordinate of those targets including latitude longitude and altitude. Assuming those coordinates are tx, ty and tz, respectively, and the current location of the device is x, y and z.
Based on colinearity equations in photogrammetry, the screen coordinates of the target (sx, sy) are:
sx = f*{[m11(x-tx)+m12(y-ty)+m13(z-tz)]/[m31(x-tx)+m32(y-ty)+m33(z-tz)]}
sy = f*{[m21(x-tx)+m22(y-ty)+m23(z-tz)]/[m31(x-tx)+m32(y-ty)+m33(z-tz)]}
where f is focal length, and m11 ~ m33 are values in rotation matrix based on device orientation. Screen coordinates must be applied with an affine transformation to turn them into screen column and rows for printing usages.
This is what I was trying to do, but I found out that focal length never changed after autofocus is applied. So I do it in an alternative way.
- Get the screen size(or preview size) and camera horizontal and vertical angle of your device.
- Calculate the Azimuth and Inclination angle between device and the target.
- Interpolate the screen coordinates based on these angles and screen sizes.
- Print targets on screen. I set up a set of imageviews and textviews to do the same thing.
For real time updates of these targets, try to update them in onSensorChanged()
Hope these help. :)
回答2:
The faq clearly says that you shouldn't ask poorly scoped questions. What you are asking is not 'how to link them' because what you need is by no means a short and answerable question.
But I can recommend you to buy this book, it is pretty nice explained and guides the reader to accomplish almost exactly what you want to do: http://www.apress.com/9781430239451
Don't forget to download the several source projects the author included. Start from there and if you need help in more specific problems start a new and concise question.
Have a nice day.
回答3:
You may be looking for a SurfaceView. I haven't made extensive use of it myself but I know that this is how the ZXing Barcode Scanner superimposes images over the camera preview. Checkout the developer guide:
http://developer.android.com/reference/android/view/SurfaceView.html
and also the ZXing source code for a real application:
https://code.google.com/p/zxing/source/browse/trunk/android/src/com/google/zxing/client/android/CaptureActivity.java
来源:https://stackoverflow.com/questions/15308329/mapping-gps-locations-on-the-camera-preview-in-android