SensorManager sensorManager =
(SensorManager)getSystemService(Context.SENSOR_SERVICE);
if (sm.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD) != null)
SensorEventListener sensorList = new SensorEventListener() {
@Override
public void onSensorChanged(SensorEvent event) {
//Llevar a cabo la acción
}
@Override
public void onAccuracyChanged(Sensor sensor, int accuracy) {
// TODO Auto-generated method stub
}
};
sm.registerListener(sensorList, sm.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD),SensorManager.SENSOR_DELAY_FASTEST);
SensorEventListener mySensorListener = new SensorEventListener() {
@Override
public void onSensorChanged(SensorEvent event) {
Double val3 = Double.valueOf(d.format((double) event.values[2]));
DecimalFormat d = new DecimalFormat("000");
Double val1 = Double.valueOf(d.format((double) event.values[0]));
Double val2 = Double.valueOf(d.format((double) event.values[1]));
t1.setText("x:" + val1.toString());
t2.setText("y:" + val2.toString());
t3.setText("z:" + val3.toString());
float average = (values[0]+values[1]+values[2])/3;
float modValue = Math.abs(average);
mIndicator.setProgress((int)modValue);
}
LocationListener locationListener = new LocationListener() {
public void onLocationChanged(Location location) {
//makeUseOfNewLocation(location);
Log.v("GPS", ((Double)location.getLatitude()).toString());
}
public void onStatusChanged(String provider, int status, Bundle extras) {
}
public void onProviderEnabled(String provider) {
}
public void onProviderDisabled(String provider) {
}
l = gc.getFromLocation(location.getLatitude(),location.getLongitude(), 5);