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 package com.magnet_test; import android.hardware.Sensor; public class Magnet_Listener implements SensorEventListener { private float[] magneticFieldValues; @Override } @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) { > Basically, it seems like they are using the x component of the force 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.
| ||||||||||||||