Android :: Finding Direction Using Compass Interface
Jan 11, 2010I need to know if there is an interface to access the direction in which the phone is pointing.
View 2 RepliesI need to know if there is an interface to access the direction in which the phone is pointing.
View 2 RepliesI'm trying to implement something that I don't even know if it's possible. So I have this class which implements a SensorEventListener like this:
private SensorEventListener mySensorEventListener = new SensorEventListener(){
@Override public void onAccuracyChanged(Sensor sensor, int accuracy) {
} @Override public void onSensorChanged(SensorEvent event) {
myCompass.updateDirection((float)event.values[0]); } };
And a class that handles the way the compass looks like this:
public static class compassLook extends View {
private Paint paintPointer = new Paint(Paint.ANTI_ALIAS_FLAG);
private Paint paintCircle = new Paint(Paint.ANTI_ALIAS_FLAG);
private Paint paintLeters = new Paint(Paint.ANTI_ALIAS_FLAG);
private boolean firstDraw; private float direction = 0 ;
public compassLook(Context context) { super(context); init();
} public compassLook(Context context, AttributeSet attrs) { super(context, attrs); init();
} public compassLook(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle); init(); } private void init(){
paintPointer.setStyle(Paint.Style.STROKE); paintPointer.setStrokeWidth(3);
paintPointer.setColor(Color.argb(255, 209, 114, 2)); paintCircle.setStyle(Paint.Style.STROKE);
paintCircle.setStrokeWidth(2); paintCircle.setColor(Color.argb(150, 255, 255, 255));
paintLeters.setStyle(Paint.Style.STROKE); paintLeters.setStrokeWidth(1);
paintLeters.setColor(Color.argb(230, 255, 255, 255)); paintLeters.setTextSize(12);
firstDraw = true; } @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { setMeasuredDimension(MeasureSpec.getSize(widthMeasureSpec),
MeasureSpec.getSize(heightMeasureSpec)); } @Override protected void onDraw(Canvas canvas) {
int cxCompass = (getMeasuredWidth()/2); int cyCompass = (getMeasuredHeight()/2);
float radiusCompass; if(cxCompass > cyCompass){ radiusCompass = (float) (cyCompass * 0.9);
} else{ radiusCompass = (float) (cxCompass * 0.9);}
canvas.drawCircle(cxCompass-50, cyCompass, radiusCompass, paintCircle);
if(!firstDraw){ // Desenho da linha que aponta canvas.drawLine(cxCompass-50, cyCompass,
(float)(cxCompass-50 + radiusCompass * Math.sin((double)(- direction) * 3.14/180)),
(float)(cyCompass - radiusCompass * Math.cos((double)(-direction) * 3.14/180)),
paintPointer); double mLatitude = (mLocation.getLatitude() / 1E6);
// I get this value from a LM request double mLongitude = (mLocation.getLongitude() / 1E6);
// I get this value from a LM request double picLatitude= Double.parseDouble(picLatitudeString);
// I get this value from a bundle double picLongitude = Double.parseDouble(picLongitudeString);
// I get this value from a bundle float direction = (float)
Math.toDegrees(Math.atan2(picLongitude- mLongitude, picLatitude-mLatitude));
float distancia = (float) (Math.sqrt(Math.pow(mLatitude- picLatitude,
2) + Math.pow(mLongitude-picLongitude,2)))/2;
//Desenho do texto que indica a distancia
canvas.drawText(String.valueOf(distancia) + "Km", cxCompass-30,
cyCompass+20, paintLeters); } } public void updateDirection(float dir)
{ firstDraw = false; direction = dir; invalidate(); } }
I'm a bit new to Android but after searching on the Market, the web and this forum, I can't seem to find anything like this but I feel like it has to exist (or hopefully will soon). I'm looking for a camera application that can place the current compass direction on the image (and stamp the saved image with the direction). The tilt of the phone would be cool to have, too, but just the compass would be great. I did find an application that shows the compass direction on over top of a feed from the camera ("Reality + Compass" by Udell Enterprises).
I want something just like this, but with the ability to save the image. In case you're wondering, I'd like to use this for bettering the storm spotting community. A problem when people send in images of clouds/storms/tornadoes/etc is that you never know (1) where the picture was taken and (2) in what direction. Ideally GPS location could be added, too, but for now I just want the compass. (Other image services can handle the location part fine, like Twitter for Android/Twitpic.)
(I'm on the HTC Aria, but I can sideload apps now thanks to the new version of HTC Sync.)
Every one can any body explain to me how I can get direction in Htc desire ,cause when I ask about any direction or end point always the answer is no route.
View 6 Replies View RelatedI've been playing with the data given by the accelerometer,trying to work out how I can gauge a shake from front to back or side to side. This all seems straightforward enough.But I'd love to know the direction of the shake. So, if the user is shaking backwards and forwards, I want to know if the device is moving away from the user, or back towards him/her. I can't find any way of telling this.
View 6 Replies View RelatedI want to show the direction information in my app.Direction from one address to the another using Google maps and also wanted to set overlays at the starting address and the destination address.Is there any classes in android too do that.
View 5 Replies View RelatedI am creating a class extending mylocationoverlay. then, i override the draw method. is this the correct method? because after i rewrote the draw method, the map tile cannot render.
View 4 Replies View RelatedScrolling on an Android phone makes sense because it's like you're physically sliding the page upwards. However, now that I'm used to doing that, when I get on my laptop and start to scroll with my touchpad, sometimes I find myself scrolling the wrong direction. On a touchpad you drag downwards to go down on the page, or to slide the page upwards. So it's backwards from the motion you would make on your phone.
View 17 Replies View RelatedI'm trying to create a compass for my application BUT the difference is that, instead of having a line always pointing to north, I want this line to point for a specific point. I've been trying dozens of algorithms and nothing works. I've finally found one that points me exactlly to the point I want. But it doesn't move if I change the position of the device which is my objective. Basically, what I want is that no matter the direction I'm using my device. The line always point me to the point (picLatitude,picLongitude). I understood that for the line to move, I can't use static variables. I need to use the values offered by the onSensorChanged(SensorEvent event). This are the data I have available:
event.values[0]: azimuth, rotation around the Z axis (device in relation to north, 0º) event.values[1]: pitch, rotation around the X axis event.values[2]: roll, rotation around the Y axis mLatitude: device current latitude got from GPS (variable) mLongitude: device current longitude got from GPS (variable) picLatitude: static picture latitude established previously picLongitude: static picture longitude established previously distance: distance in Km from device to the picture calculated previously
And this the formula that works correct, and gives me the correct angle. (But it doesn't use any of the Sensor Data so the line Compass doesn't move):
double dLong = picLongitude - mLongitude; double y = (Math.sin(dLong) *
Math.cos(picLatitude)); double x = (Math.cos(mLatitude) * Math.sin(picLatitude) - Math.sin(mLatitude)*Math.cos(picLatitude)*Math.cos(dLong)); double angleDegreesWrongRange = Math.abs(Math.toDegrees(Math.atan2(y, x))); float angleDegrees = (float) ((angleDegreesWrongRange+360) % 360);
myCompass.updateDirection(angleDegrees);
I got this "bearing" formula from this website: http://www.movable-type.co.uk/scripts/latlong.html. I've try adding, subtracting, the azimuth.. I've tried with the others, seriously at this point I'm just demoralized.
Is there an easy to know the direction of scroll (up or down for a vertical list) and the scroll velocity for ListView's?
View 2 Replies View RelatedIs there any way to find the direction between two locations in Android?
View 3 Replies View RelatedI am wondering whether it is possible to detect voice direction in android or not? For example on nexus one using the actual mic and the noise cancellation mic or using any other method?
View 4 Replies View RelatedMy current app flies in a sub activity when you flick-up. Problem is, it flies in horizontally from the right. I want it to fly in vertically from the bottom to match the flick direction. I'm sure this must be an xml property somewhere, but I can't find it. Does someone have a pointer as to how to set this?
View 10 Replies View RelatedI am using Tablet skin for running emulator output. All the menu and list items are displayed properly e.g. Horizontally whereas Videos are being played vertically. How can I change the direction of video? Kindly reply as soon as possible.
View 2 Replies View RelatedHow to play video in a time reversed direction? The requirement is to loop playing forward and backward repeatedly.
View 7 Replies View RelatedI want to show the direction on the screen that phone is facing.
For example:
0
|- []
|_
South --- North
In the above diagram the phone would display "North". Since the user (the stick with 0 for his head) is holding out the phone (the [] in the diagram) pointing north.
I found this example. I understand what it's doing except it seems to calculate yaw, pitch, roll, and inclination. What are those and how would I use them to simply find which way the phone is pointing?
Also this android documentation mentions X, Y, and Z axises but I don't see anywhere that says how those axises correspond to the phone? Is Z going from the bottom of the phone to the top?
I want to ask that is that possible do in android catch the in the touch mode catch the scrolling direction ? When user touch on the screen left to right, can I catch the change ?
If it is possible which listener can ı use ?
I found some of the methods and listeners but I 'm not sure that therse are represent my requirement .
http://developer.android.com/reference/android/text/method/Touch.html
Public Methods
static int getInitialScrollX(TextView widget, Spannable buffer)
static int getInitialScrollY(TextView widget, Spannable buffer)
I would like to know how I can change the direction (up or down) of an AutocompleteTextview drop down list.
View 2 Replies View RelatedAfter launching Android maps application from other application, how to get driving direction info from maps application? e.g. distance, estimated driving time, etc.
View 6 Replies View RelatedDoes Android 3.2 smartphones all support arrow/direction keys? If so, what are the keyCode for the four keys?
does KeyEvent class already defined these keys?
I want to ask that is that possible do in android catch the in the touch mode catch the scrolling direction ? When user touch on the screen left to right, can I catch the change ? If it is possible which listener can ı use ?
I found some of the methods and listeners but I 'm not sure that therse are represent my requirement . http://developer.android.com/reference/android/text/method/Touch.html
Public Methods static int getInitialScrollX(TextView widget, Spannable buffer) static int getInitialScrollY(TextView widget, Spannable buffer)
I was having the problem in here : How to start Activity in adapter? . however, i would like to modify the transition animation direction. since, inside an adapter, you cannot call overridePendingTransition(). So do you guys know how to do it by using context and intent? also, i have an activity using my customized adapter, and do you guys know how to call my own function in activity from the adapter?
View 1 Replies View Related
I have a TranslateAnimation that shall animate a LinearLayout (isScrollContainer) to the left and to the right along the x-axis. The animation to the left works and the animation is straight - means that the view is animated horizontally only.
But the animation left to right doesn't work: instead of just moving the view from left to right along the x-axis, the view gets animated into the screen from diagonal lower-right corner. But for the Y parameters I pass fixed identical values.
Here is a flv movie that shows the animation and issue I described: http://tinyurl.com/24n4eac
Code as follows...
I am writing an Application that has multiple layouts with buttons. I have set up onClickListners for the buttons. Some buttons will change the activity and bring up a new layout with new buttons, and others will send outgoing SPP strings over Bluetooth. The strings will be defined in an XML file and will not change (serial commands).I can hard code the MAC address of the Bluetooth Server and only need to send data, not receive.
I am looking for some general guidance on the direction to go as far as setting up my Bluetooth connection and outgoing transmissions. I have looked at the BluetoothChat example extensively but do not have any good resources in the case of multiple activities.
-Do I use a separate activity to manage all Bluetooth transmissions and connections and create handlers for every case where I would send a Bluetooth message?
-Should I add Bluetooth connection+transmission threads in every activity (seems like i would run into issues losing the connection when changing activities)?
-Can I use handlers that are not class specific where the BluetoothService Activity could send whatever was prompted by the active/current activity?
-Could I just hard code all strings to be sent in the BluetoothService Activity and the UI activity could prompt the BluetoothService Activity to send the requested string based on the button click?
I'm trying to use the JJIL libraries with my Android project:
http://code.google.com/p/jjil/
I followed all the instructions on importing libraries into eclipse on the android guides, and have had no successes. It just fails to import.
Can some one point me in the right direction with this?
I have the HTC hero right now with the Android 1.5 and was wondering if there is a compass app that i can download which is similar to the iPhone 3GS?
View 4 Replies View RelatedI've modified the code a bit since the last time, and now it crashes at runtime. I've got the log-cat and code below. how to go about debugging.
CODE:..................
I'm trying to make a map with showing my location with an arrow that point to the way we are facing. the arraw image is something like this:
^ 0
Always pointing north, so i rotate it with sensor orientation event ( image.rotate(values[0]) )
I would like to ask if google map's north is always on 12 o'clock? because i try sometimes the arrow point to wrong direction. how to accurately make this thing works?
I have a marker on the map using an Overlay. I also have access to the compass sensor which I'm able to show a textView with the orientation values (0 to 359). How can I apply this values to the marker? (which is a drawable). I already have a MAtrix created but when I insert the orientation value gives me an error, here it is:
GeoPoint geopoint = new GeoPoint((int) (newLocation.getLatitude() * 1E6),
(int) (newLocation.getLongitude() * 1E6)); Paint paint = new Paint();
Point pt = new Point(); mapView.getProjection().toPixels(geopoint, pt);
Bitmap bmp = BitmapFactory.decodeResource(getResources(),R.drawable.user2);
Matrix matrix = new Matrix(); matrix.postTranslate(-25, -25);
matrix.postRotate(direction); matrix.postTranslate(pt.x, pt.y);
paint.setAntiAlias(true); paint.setFilterBitmap(true);
int width = bmp.getWidth(); int height = bmp.getHeight();
Bitmap changedBitmap = Bitmap.createBitmap(bmp, 0, 0, width, height, matrix, true);
BitmapDrawable icon = new BitmapDrawable(changedBitmap);
icon.setBounds(0, 0, icon.getIntrinsicWidth(), icon.getIntrinsicHeight());
userOverlay useroverlay = new userOverlay(icon); useroverlay.addItem(item);
mapView.getOverlays().add(useroverlay);
I used the value retrieved from the sensor on "direction" but it doesn't work.
Am researching a problem with compass and sensor values returned by the phone. I found this thread: http://groups.google.com/group/android-developers/browse_thread/threa. Which seems related, but it's old so I'm starting a new one. I'm getting stuck values from both the compass and orientation sensors. It was fine yesterday, but today, I'm only getting values in a limited range (e.g. compass headings from 240 - 290), no matter how I orient the device. What's even more odd is that the radians returned from the call to Sensor Manager.get Orientation(), which returns radians, is giving consistently out of range values. Anyone see this same behavior, and if so, any fixes? Here's some sample sensor data. Format is heading, pitch, roll. The first set contains raw values, the second set contains values after I've applied the orientation matrix generated by the Sensor Manager. The third set contains values after I've smoothed the data with my own algorithm.
View 4 Replies View Related