diff --git a/ShowMe/ShowMeX/src/com/showmehills/HillDatabase.java b/ShowMe/ShowMeX/src/com/showmehills/HillDatabase.java index 0aca8e7..5f1b37a 100644 --- a/ShowMe/ShowMeX/src/com/showmehills/HillDatabase.java +++ b/ShowMe/ShowMeX/src/com/showmehills/HillDatabase.java @@ -152,7 +152,7 @@ public void SetDirections(Location curLocation) } } while (cursor.moveToNext()); } - + Log.d("showmehills", "Added " + localhills.size() + " markers"); /* localhills.add(new Hills(0,"London Eye", -0.119700, 51.5033, 135)); localhills.add(new Hills(0,"Shard", -0.086667, 51.504444, 308)); diff --git a/ShowMe/ShowMeX/src/com/showmehills/LocationResolver.java b/ShowMe/ShowMeX/src/com/showmehills/LocationResolver.java index be96cc8..9890d21 100644 --- a/ShowMe/ShowMeX/src/com/showmehills/LocationResolver.java +++ b/ShowMe/ShowMeX/src/com/showmehills/LocationResolver.java @@ -18,7 +18,8 @@ public LocationResolver(LocationManager lm, String provider, RapidGPSLock locati this.locationMgrImpl = locationMgrImpl; } public void onLocationChanged(Location location) { - Log.d("showmehills", "new location " + location.getAccuracy() + " " + location.getLatitude() + "," + location.getLongitude()); + + Log.d("showmehills", "new location (" + provider + ") " + location.getAccuracy() + " " + location.getLatitude() + "," + location.getLongitude()); lm.removeUpdates(this); locationMgrImpl.locationCallback(provider); } diff --git a/ShowMe/ShowMeX/src/com/showmehills/MapOverlay.java b/ShowMe/ShowMeX/src/com/showmehills/MapOverlay.java index a88a1cf..d8031e4 100644 --- a/ShowMe/ShowMeX/src/com/showmehills/MapOverlay.java +++ b/ShowMe/ShowMeX/src/com/showmehills/MapOverlay.java @@ -79,8 +79,8 @@ public void onCreate(Bundle savedInstanceState) { accelerometer = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER); magnetometer = mSensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD); - mSensorManager.registerListener(this, accelerometer, SensorManager.SENSOR_DELAY_UI); - mSensorManager.registerListener(this, magnetometer, SensorManager.SENSOR_DELAY_UI); + mSensorManager.registerListener(this, accelerometer, SensorManager.SENSOR_DELAY_GAME); + mSensorManager.registerListener(this, magnetometer, SensorManager.SENSOR_DELAY_GAME); myDbHelper = new HillDatabase(this); try { @@ -106,8 +106,8 @@ protected void onResume() { Log.d("showmehills", "onResume"); super.onResume(); - mSensorManager.registerListener(this, accelerometer, SensorManager.SENSOR_DELAY_UI); - mSensorManager.registerListener(this, magnetometer, SensorManager.SENSOR_DELAY_UI); + mSensorManager.registerListener(this, accelerometer, SensorManager.SENSOR_DELAY_GAME); + mSensorManager.registerListener(this, magnetometer, SensorManager.SENSOR_DELAY_GAME); try { myDbHelper.openDataBase(); @@ -240,9 +240,9 @@ public void onAccuracyChanged(Sensor sensor, int accuracy) { } public void onSensorChanged(SensorEvent event) { - if (event.accuracy == SensorManager.SENSOR_STATUS_UNRELIABLE) { + /*if (event.accuracy == SensorManager.SENSOR_STATUS_UNRELIABLE) { return; - } + }*/ if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER) mGravity = event.values; if (event.sensor.getType() == Sensor.TYPE_MAGNETIC_FIELD) mGeomagnetic = event.values; diff --git a/ShowMe/ShowMeX/src/com/showmehills/RapidGPSLock.java b/ShowMe/ShowMeX/src/com/showmehills/RapidGPSLock.java index 38af31b..6ff04d6 100644 --- a/ShowMe/ShowMeX/src/com/showmehills/RapidGPSLock.java +++ b/ShowMe/ShowMeX/src/com/showmehills/RapidGPSLock.java @@ -71,6 +71,7 @@ public void locationCallback(String provider) bestLocationProvider = provider; } setLocationAtLastDownload(curLoc); + mixContext.UpdateMarkers(); } private void requestBestLocationUpdates() diff --git a/ShowMe/ShowMeX/src/com/showmehills/ShowMeHillsActivity.java b/ShowMe/ShowMeX/src/com/showmehills/ShowMeHillsActivity.java index 2ed692c..91c263a 100644 --- a/ShowMe/ShowMeX/src/com/showmehills/ShowMeHillsActivity.java +++ b/ShowMe/ShowMeX/src/com/showmehills/ShowMeHillsActivity.java @@ -71,6 +71,8 @@ public class ShowMeHillsActivity extends Activity implements SensorEventListener float[] mGeomagnetic; Timer timer = new Timer(); + private int GPSretryTime = 15; + private int CompassSmoothingWindow = 50; //private Location curLocation; private String acc = ""; @@ -139,8 +141,8 @@ protected void onResume() { Log.d("showmehills", "onResume"); super.onResume(); - mSensorManager.registerListener(this, accelerometer, SensorManager.SENSOR_DELAY_UI); - mSensorManager.registerListener(this, magnetometer, SensorManager.SENSOR_DELAY_UI); + mSensorManager.registerListener(this, accelerometer, SensorManager.SENSOR_DELAY_GAME); + mSensorManager.registerListener(this, magnetometer, SensorManager.SENSOR_DELAY_GAME); mGPS.switchOn(); getPrefs(); wl.acquire(); @@ -189,7 +191,7 @@ public void onCreate(Bundle savedInstanceState) { mGPS = new RapidGPSLock(this); mGPS.switchOn(); mGPS.findLocation(); - timer.scheduleAtFixedRate(new LocationTimerTask(),20* 1000,20* 1000); //wait 20 seconds for the location updates to find the location + timer.scheduleAtFixedRate(new LocationTimerTask(),GPSretryTime* 1000,GPSretryTime* 1000); mSensorManager = (SensorManager)getSystemService(SENSOR_SERVICE); @@ -266,27 +268,34 @@ public boolean onOptionsItemSelected(MenuItem item) { return super.onOptionsItemSelected(item); } + public void UpdateMarkers() + { + Location curLocation = mGPS.getCurrentLocation(); + myDbHelper.SetDirections(curLocation); + } + class filteredDirection { - int AVERAGINGWINDOW = 10; double dir; - double sinevalues[] = new double[AVERAGINGWINDOW]; - double cosvalues[] = new double[AVERAGINGWINDOW]; + double sinevalues[] = new double[CompassSmoothingWindow]; + double cosvalues[] = new double[CompassSmoothingWindow]; int index = 0; + int outlierCount = 0; + void AddLatest( double d ) { sinevalues[index] = Math.sin(d); cosvalues[index] = Math.cos(d); index++; - if (index > AVERAGINGWINDOW - 1) index = 0; + if (index > CompassSmoothingWindow - 1) index = 0; double sumc = 0; double sums = 0; - for (int a = 0; a < AVERAGINGWINDOW; a++) + for (int a = 0; a < CompassSmoothingWindow; a++) { sumc += cosvalues[a]; sums += sinevalues[a]; } - dir = Math.atan2(sums/AVERAGINGWINDOW,sumc/AVERAGINGWINDOW); + dir = Math.atan2(sums/CompassSmoothingWindow,sumc/CompassSmoothingWindow); } double getDirection() @@ -303,24 +312,24 @@ int GetVariation() double Q = 0; double sumc = 0; double sums = 0; - for (int a = 0; a < AVERAGINGWINDOW; a++) + for (int a = 0; a < CompassSmoothingWindow; a++) { sumc += cosvalues[a]; sums += sinevalues[a]; } - double avgc = sumc/AVERAGINGWINDOW; - double avgs = sums/AVERAGINGWINDOW; + double avgc = sumc/CompassSmoothingWindow; + double avgs = sums/CompassSmoothingWindow; sumc = 0; sums = 0; - for (int a = 0; a < AVERAGINGWINDOW; a++) + for (int a = 0; a < CompassSmoothingWindow; a++) { sumc += Math.pow(cosvalues[a] - avgc, 2); sums += Math.pow(sinevalues[a] - avgs, 2); } - Q = (sumc/(AVERAGINGWINDOW-1)) + (sums/(AVERAGINGWINDOW-1)); + Q = (sumc/(CompassSmoothingWindow-1)) + (sums/(CompassSmoothingWindow-1)); - return (int)(Q*10000); + return (int)(Q*1000); } }