I'm developing a simple AR app what must calculate user GPS position and show his latitude, longitude and compass & accelerometer values on textviews on the screen (in top of the camera view).
Something is going wrong, because i only can capture compass direction value, but i can't capture GPS positions (lat, lon).... and also i can't capture accelerometer values (inclination, Direction2, kFilteringFactor, aboveOrBelow). I dont understand why i can't do it. When i use my code for capture GPS positions on another app, it works OK, and captures the GPS positions of the user correctly, but when i use the code here it doesn't captures nothing. I know that my working code for capturing gps positions doesn't works when i use on this AR app because this: I am writing on the screen, in the top of the camera, the values captured by compass, gps, and accelerometer, and only compass direction value is written on the screen. for the cameraView i'm using the default cameraView code written on this guide: http://www.devx.com/wireless/article/42482/1954 and this is my main class: public class AugmentedRealitySampleActivity extends Activity implements Runnable{ private CustomCameraView cv=null; private TextView tv1; private TextView tv2; private TextView tv3; private TextView tv4; private TextView tv5; private TextView tv6; public static SensorManager sensorMan; //variables para obtener mi posicion: LocationManager mLocationManager; Location mLocation; MyLocationListener mLocationListener; Location currentLocation = null; private float direction; //compass //private Location curLocation; //gps public volatile float inclination; //accelerometer double lat=-1; double lon=-1; public void onCreate(Bundle savedInstanceState) { //try{ super.onCreate(savedInstanceState); cv = new CustomCameraView(this.getApplicationContext()); FrameLayout rl = new FrameLayout(this.getApplicationContext()); LinearLayout ll= new LinearLayout(this.getApplicationContext()); ll.setOrientation(LinearLayout.VERTICAL); setContentView(rl); rl.addView(cv); rl.addView(ll); //} catch(Exception e){} tv1=new TextView(getApplicationContext()); tv2=new TextView(getApplicationContext()); tv3=new TextView(getApplicationContext()); tv4=new TextView(getApplicationContext()); tv5=new TextView(getApplicationContext()); tv6=new TextView(getApplicationContext()); tv1.setBackgroundColor(Color.BLACK); tv2.setBackgroundColor(Color.BLACK); //tv3.setBackgroundColor(Color.BLACK); //tv4.setBackgroundColor(Color.BLACK); //tv5.setBackgroundColor(Color.BLACK); //tv6.setBackgroundColor(Color.BLACK); ll.addView(tv1); ll.addView(tv2); ll.addView(tv3); ll.addView(tv4); ll.addView(tv5); ll.addView(tv6); sensorMan = (SensorManager) getSystemService(Context.SENSOR_SERVICE); sensorMan.registerListener(Compasslistener, sensorMan.getDefaultSensor(SensorManager.SENSOR_ORIENTATION), SensorManager.SENSOR_DELAY_FASTEST); sensorMan.registerListener(Accelerometerlistener, sensorMan.getDefaultSensor(Sensor.TYPE_ACCELEROMETER), SensorManager.SENSOR_DELAY_FASTEST); //LocationManager locMan; //locMan = (LocationManager)getSystemService(Context.LOCATION_SERVICE); //locMan.requestLocationUpdates(LocationManager.GPS_PROVIDER, 100, 0, gpsListener); //getLatitude(); getLongitude(); bearingTo(); distanceTo(); tv1.setText("Test1"); tv2.setText("Test2"); tv3.setText("Test3"); tv4.setText("Test4"); tv5.setText("Test5"); tv6.setText("Test6"); Thread thread = new Thread(this); thread.start(); } //////////////////////////////////////////////// //COMPASS: //////////////////////////////////////////////// SensorEventListener Compasslistener = new SensorEventListener() { public void onAccuracyChanged(Sensor arg0, int accuracy){ } public void onSensorChanged(SensorEvent evt) { float vals[] = evt.values; direction = vals[0]; tv1.setText("Direction= " + direction); } }; //////////////////////////////////////////////// //ACCELEROMETER: //////////////////////////////////////////////// private SensorEventListener Accelerometerlistener = new SensorEventListener() { public volatile float direction = (float) 0; //public volatile float rollingZ = (float)0; public volatile float kFilteringFactor = (float)0.05; public float aboveOrBelow = (float)0; public void onAccuracyChanged(Sensor arg0, int arg1){} public void onSensorChanged(SensorEvent evt) { float vals[] = evt.values; if(evt.sensor.getType() == Sensor.TYPE_ORIENTATION) { float rawDirection = vals[0]; direction =(float) ((rawDirection * kFilteringFactor) + (direction * (1.0 - kFilteringFactor))); inclination = (float) ((vals[2] * kFilteringFactor) + (inclination * (1.0 - kFilteringFactor))); if(aboveOrBelow > 0) inclination = inclination * -1; if(evt.sensor.getType() == Sensor.TYPE_ACCELEROMETER) aboveOrBelow = (float) ((vals[2] * kFilteringFactor) + (aboveOrBelow * (1.0 - kFilteringFactor))); tv3.setText("Inclination= " + inclination); tv4.setText("Direction2= " + direction); tv5.setText("kFilteringFactor= " + kFilteringFactor); tv6.setText("aboveOrBelow= " + aboveOrBelow); } } }; //////////////////////////////////////////////////////////////////////// //Métodos del Hilo que obtiene la posicion GPS del usuario periodicamente. /////////////////////////////////////////////////////////////////////// public void run() { mLocationManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE); if (mLocationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) { Looper.prepare(); mLocationListener = new MyLocationListener(); try{ mLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 200, 0, mLocationListener); }catch(Exception e){} //try { // wait(100); //}catch (InterruptedException e) {} Looper.loop(); } } private class MyLocationListener implements LocationListener { public void onLocationChanged(Location loc) { if (loc != null) { try{ currentLocation = loc; handler.sendEmptyMessage(0); }catch(Exception e){} } } public void onProviderDisabled(String provider) { } public void onProviderEnabled(String provider) { } public void onStatusChanged(String provider, int status, Bundle extras) { } } private Handler handler = new Handler() { public void handleMessage(Message msg) { if (currentLocation!=null) { lat=currentLocation.getLatitude(); lon=currentLocation.getLongitude(); if (lat==-1 && lon ==-1) /// si no existe ninguna posicion GPS anterior en el telefono, no hago nada { } else //// si existe alguna posicion anterior (es decir, si el GPS del telefono ha sido activado al menos alguna vez en su vida util) { tv2.setText("Location= "+lat+" "+lon); } } } }; } -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en