Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion making an android compass
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
bob  
View profile  
 More options Sep 27 2012, 2:44 pm
From: bob <b...@coolfone.comze.com>
Date: Thu, 27 Sep 2012 11:44:41 -0700 (PDT)
Local: Thurs, Sep 27 2012 2:44 pm
Subject: Re: making an android compass

Here is the *correct* (until proven otherwise) version of a compass for a
device lying flat on a table:

package com.magnet_test;

import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;

public class Magnet_Listener implements SensorEventListener {

private float[] magneticFieldValues;

@Override
public void onAccuracyChanged(Sensor sensor, int accuracy) {

}

@Override
public void onSensorChanged(SensorEvent sensorEvent) {
if (sensorEvent.sensor.getType() == Sensor.TYPE_MAGNETIC_FIELD)
magneticFieldValues = sensorEvent.values;
 float x = magneticFieldValues[0];
float y = magneticFieldValues[1];
 float angle = (float) Math.atan2(y, x);
 float angle_in_degrees = (float) Math.toDegrees(angle) + 180;
 System.out.println("angle = " + angle_in_degrees);

}
}

*Inspired by code from Reto Meier.*
On Thursday, September 27, 2012 10:33:31 AM UTC-5, bob wrote:

> So, I'm trying to learn how to make an android compass.

> Naturally, I used a site called google and typed the following in:

> "making an android compass"

> I found myself at this URL:

> http://android-er.blogspot.com/2010/08/simple-compass-sensormanager-a...

> After looking thru it, I'm thinking it's incorrect.

> There is this suspiciously simple method:

> public void onSensorChanged(SensorEvent event) {
>  // TODO Auto-generated method stub
>  myCompassView.updateDirection((float)event.values[0]);
> }

> Basically, it seems like they are using the x component of the force
> vector as if it were an angle.  Can someone else look at this and let me
> know what you think?


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.