diff --git a/res/values/generators.xml b/res/values/generators.xml
index cd52c21..a6e8f0e 100755
--- a/res/values/generators.xml
+++ b/res/values/generators.xml
@@ -65,7 +65,7 @@
This app will not use your location, but use an placeholder instead.
Locally Randomized
- Please enter the random distance (miles/kilometers)to use to obfuscate your exact location:
+ Please enter the random distance (kilometers) to use to obfuscate your exact location:
User Provided
Please enter a postal code or city and province to use as your location:
diff --git a/src/com/audacious_software/passive_data_kit/generators/device/Location.java b/src/com/audacious_software/passive_data_kit/generators/device/Location.java
index 64c74b0..7428d53 100755
--- a/src/com/audacious_software/passive_data_kit/generators/device/Location.java
+++ b/src/com/audacious_software/passive_data_kit/generators/device/Location.java
@@ -67,8 +67,10 @@
import java.io.File;
import java.io.IOException;
+import java.security.SecureRandom;
import java.util.ArrayList;
import java.util.List;
+import java.util.Random;
@SuppressWarnings("unused")
public class Location extends Generator implements GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener, LocationListener {
@@ -312,13 +314,42 @@ public void onConnectionFailed(ConnectionResult connectionResult) {
@Override
public void onLocationChanged(android.location.Location location) {
- Log.e("PDK", "LOCATION CHANGED");
-
if (location == null)
return;
long now = System.currentTimeMillis();
+ final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this.mContext);
+ int selected = prefs.getInt(Location.ACCURACY_MODE, Location.ACCURACY_BEST);
+
+ if (selected == Location.ACCURACY_RANDOMIZED) {
+ // http://gis.stackexchange.com/a/68275/10230
+
+ double latitude = location.getLatitude();
+ double longitude = location.getLongitude();
+
+ double radius = prefs.getLong(Location.ACCURACY_MODE_RANDOMIZED_RANGE, Location.ACCURACY_MODE_RANDOMIZED_RANGE_DEFAULT);
+
+ double radiusInDegrees = radius / 111000;
+
+ Random r = new SecureRandom();
+
+ double u = r.nextDouble();
+ double v = r.nextDouble();
+
+ double w = radiusInDegrees * Math.sqrt(u);
+ double t = 2 * Math.PI * v;
+ double x = w * Math.cos(t);
+ double y = w * Math.sin(t);
+
+ // Adjust the x-coordinate for the shrinking of the east-west distances
+ longitude = longitude + (x / Math.cos(latitude));
+ latitude = y + latitude;
+
+ location.setLongitude(longitude);
+ location.setLatitude(latitude);
+ }
+
ContentValues values = new ContentValues();
values.put(Location.HISTORY_OBSERVED, System.currentTimeMillis());
values.put(Location.HISTORY_LATITUDE, location.getLatitude());
@@ -913,6 +944,34 @@ public android.location.Location getLastKnownLocation() {
}
}
+ if (selected == Location.ACCURACY_RANDOMIZED) {
+ // http://gis.stackexchange.com/a/68275/10230
+
+ double latitude = last.getLatitude();
+ double longitude = last.getLongitude();
+
+ double radius = prefs.getLong(Location.ACCURACY_MODE_RANDOMIZED_RANGE, Location.ACCURACY_MODE_RANDOMIZED_RANGE_DEFAULT);
+
+ double radiusInDegrees = radius / 111000;
+
+ Random r = new SecureRandom();
+
+ double u = r.nextDouble();
+ double v = r.nextDouble();
+
+ double w = radiusInDegrees * Math.sqrt(u);
+ double t = 2 * Math.PI * v;
+ double x = w * Math.cos(t);
+ double y = w * Math.sin(t);
+
+ // Adjust the x-coordinate for the shrinking of the east-west distances
+ longitude = longitude + (x / Math.cos(latitude));
+ latitude = y + latitude;
+
+ last.setLongitude(longitude);
+ last.setLatitude(latitude);
+ }
+
return last;
}