diff --git a/Arbiter-Android/assets/www/js/Arbiter/Cordova/Cordova.js b/Arbiter-Android/assets/www/js/Arbiter/Cordova/Cordova.js
index fbc937d..a6c96c9 100644
--- a/Arbiter-Android/assets/www/js/Arbiter/Cordova/Cordova.js
+++ b/Arbiter-Android/assets/www/js/Arbiter/Cordova/Cordova.js
@@ -308,6 +308,12 @@ Arbiter.Cordova = (function() {
cordova.exec(null, null, "ArbiterCordova",
"dismissDownloadingSchemasProgress", []);
+ },
+
+ alertGeolocationError: function(msg){
+
+ cordova.exec(null, null, "ArbiterCordova",
+ "alertGeolocationError", [msg]);
}
};
})();
\ No newline at end of file
diff --git a/Arbiter-Android/assets/www/js/Arbiter/Cordova/Project.js b/Arbiter-Android/assets/www/js/Arbiter/Cordova/Project.js
index 1e61eff..ae481ab 100644
--- a/Arbiter-Android/assets/www/js/Arbiter/Cordova/Project.js
+++ b/Arbiter-Android/assets/www/js/Arbiter/Cordova/Project.js
@@ -1,6 +1,8 @@
Arbiter.Cordova.Project = (function(){
var describeFeatureTypeReader = new OpenLayers.Format.WFSDescribeFeatureType();
+ var includeOOMWorkaround = true;
+
var syncInProgress = false;
var getSchemaHelper = function(specificSchemas, layerId){
@@ -239,7 +241,7 @@ Arbiter.Cordova.Project = (function(){
throw "AOI layer does not exist";
}
- var findMe = new Arbiter.FindMe(map, aoiLayer);
+ var findMe = new Arbiter.FindMe(map, aoiLayer, includeOOMWorkaround);
findMe.findMe();
}catch(e){
diff --git a/Arbiter-Android/assets/www/js/Arbiter/Geolocation/FindMe.js b/Arbiter-Android/assets/www/js/Arbiter/Geolocation/FindMe.js
index d2c70a1..4af3998 100644
--- a/Arbiter-Android/assets/www/js/Arbiter/Geolocation/FindMe.js
+++ b/Arbiter-Android/assets/www/js/Arbiter/Geolocation/FindMe.js
@@ -1,7 +1,12 @@
-Arbiter.FindMe = function(olMap, olLayer){
+Arbiter.FindMe = function(olMap, olLayer, includeOOM){
this.olMap = olMap;
this.gotHighAccuracy = false;
this.olLayer = olLayer;
+
+ if(includeOOM){
+ this.oom = new Arbiter.FindMe_OOM();
+ }
+
this.minimumFindMeZoom = 18;
this.point = null;
@@ -29,6 +34,16 @@ Arbiter.FindMe = function(olMap, olLayer){
externalGraphic: this.smallBallHighAccuracy,
pointRadius: this.smallRadius
};
+
+ var context = this;
+
+ this.geolocation = new Arbiter.Geolocation(this, this.lowAccuracyCallback,
+ this.highAccuracyCallback, function(e){
+
+ if(Arbiter.Util.funcExists(context.onFailure)){
+ context.onFailure(e);
+ }
+ });
};
Arbiter.FindMe.prototype.zoom = function(position){
@@ -70,14 +85,20 @@ Arbiter.FindMe.prototype.addPoint = function(position, style){
var context = this;
this.removePointTimeoutId = window.setTimeout(function(){
- console.log("remove point timeout");
context.removePoint();
+
+ if(Arbiter.Util.existsAndNotNull(context.oom)){
+
+ context.oom.clearSavedPoint(function(){
+ console.log("FindMe removed saved point");
+ }, function(e){
+ console.log("FindMe could not removed saved point: " + JSON.stringify(e));
+ });
+ }
}, this.removePointTimeout);
this.styleChangeIntervalId = window.setInterval(function(){
-
- console.log("change style interval");
var ball = style.externalGraphic;
var radius = style.pointRadius;
@@ -132,6 +153,19 @@ Arbiter.FindMe.prototype.removePoint = function(){
this.point = null;
};
+Arbiter.FindMe.prototype.savePosition = function(position){
+ var context = this;
+
+ this.oom.savePoint(this.gotHighAccuracy,
+ position, function(){
+
+ context.zoom(position);
+ }, function(e){
+
+ context.zoom(position);
+ });
+};
+
Arbiter.FindMe.prototype.lowAccuracyCallback = function(position){
if(this.gotHighAccuracy){
@@ -139,8 +173,14 @@ Arbiter.FindMe.prototype.lowAccuracyCallback = function(position){
}
this.addPoint(position, this.lowAccuracyPointStyle);
-
- this.zoom(position);
+
+ if(Arbiter.Util.existsAndNotNull(this.oom)){
+
+ this.savePosition(position);
+ }else{
+
+ this.zoom(position);
+ }
};
Arbiter.FindMe.prototype.highAccuracyCallback = function(position){
@@ -149,24 +189,54 @@ Arbiter.FindMe.prototype.highAccuracyCallback = function(position){
this.addPoint(position, this.highAccuracyPointStyle);
- this.zoom(position);
+ if(Arbiter.Util.existsAndNotNull(this.oom)){
+
+ this.savePosition(position);
+ }else{
+
+ this.zoom(position);
+ }
};
Arbiter.FindMe.prototype.onFailure = function(e){
- console.log("FindMe could not get location");
+ var msg = "FindMe could not get location: " + JSON.stringify(e);
+
+ console.log(msg);
+
+ Arbiter.Cordova.alertGeolocationError(msg);
};
Arbiter.FindMe.prototype.findMe = function(){
+ this.geolocation.getLocation();
+};
+
+Arbiter.FindMe.prototype.resume = function(){
+
+ if(!Arbiter.Util.existsAndNotNull(this.oom)){
+ return;
+ }
+
var context = this;
- var geolocation = new Arbiter.Geolocation(this, this.lowAccuracyCallback,
- this.highAccuracyCallback, function(e){
+ this.oom.getPoint(function(findme){
- if(Arbiter.Util.funcExists(context.onFailure)){
- context.onFailure(e);
+ if(Arbiter.Util.existsAndNotNull(findme)
+ && Arbiter.Util.existsAndNotNull(findme.gotHighAccuracy)
+ && Arbiter.Util.existsAndNotNull(findme.position)){
+
+
+ if(!findme.gotHighAccuracy){
+
+ context.addPoint(findme.position, context.lowAccuracyPointStyle);
+
+ context.geolocation.getCurrentLocationHighAccuracy();
+ }else{
+
+ context.addPoint(findme.position, context.highAccuracyPointStyle);
+ }
}
+ }, function(e){
+ console.log("FindMe error loading saved position: " + JSON.stringify(e));
});
-
- geolocation.getLocation();
};
diff --git a/Arbiter-Android/assets/www/js/Arbiter/Geolocation/FindMe_OOM.js b/Arbiter-Android/assets/www/js/Arbiter/Geolocation/FindMe_OOM.js
new file mode 100644
index 0000000..03d282f
--- /dev/null
+++ b/Arbiter-Android/assets/www/js/Arbiter/Geolocation/FindMe_OOM.js
@@ -0,0 +1,80 @@
+Arbiter.SavedFindMe = function(gotHighAccuracy, position){
+ this.gotHighAccuracy = gotHighAccuracy;
+ this.position = position;
+};
+
+Arbiter.FindMe_OOM = function(){
+
+};
+
+Arbiter.FindMe_OOM.prototype.FINDME = "findme";
+
+Arbiter.FindMe_OOM.prototype.savePoint = function(gotHighAccuracy, position, onSuccess, onFailure){
+ var obj = new Arbiter.SavedFindMe(gotHighAccuracy, position);
+
+ console.log("saving point: " + obj.gotHighAccuracy);
+
+ Arbiter.PreferencesHelper.put(this.FINDME,
+ JSON.stringify(obj), this, function(){
+
+ console.log("point saved successfully: " + obj.gotHighAccuracy);
+ if(Arbiter.Util.funcExists(onSuccess)){
+ onSuccess();
+ }
+ }, function(e){
+
+ console.log("could not save point: " + obj.gotHighAccuracy);
+ if(Arbiter.Util.funcExists(onFailure)){
+ onFailure(e);
+ }
+ });
+};
+
+Arbiter.FindMe_OOM.prototype.getPoint = function(onSuccess, onFailure){
+ var context = this;
+
+ var success = function(findme){
+ if(Arbiter.Util.funcExists(onSuccess)){
+
+ if(Arbiter.Util.existsAndNotNull(findme)){
+ onSuccess(JSON.parse(findme));
+ }else{
+ onSuccess(findme);
+ }
+ }
+ };
+
+ Arbiter.PreferencesHelper.get(this.FINDME, this, function(findme){
+
+ context.clearSavedPoint(function(){
+
+ success(findme);
+ }, function(e){
+
+ console.log("Could not remove findme from preferences table: " + JSON.stringify(e));
+
+ success(findme);
+ });
+
+ }, function(e){
+
+ if(Arbiter.Util.funcExists(onFailure)){
+ onFailure(e);
+ }
+ });
+};
+
+Arbiter.FindMe_OOM.prototype.clearSavedPoint = function(onSuccess, onFailure){
+
+ Arbiter.PreferencesHelper.remove(this.FINDME, this, function(){
+
+ if(Arbiter.Util.funcExists(onSuccess)){
+ onSuccess();
+ }
+ }, function(e){
+
+ if(Arbiter.Util.funcExists(onFailure)){
+ onFailure(e);
+ }
+ });
+};
diff --git a/Arbiter-Android/assets/www/js/Arbiter/Geolocation/Geolocation.js b/Arbiter-Android/assets/www/js/Arbiter/Geolocation/Geolocation.js
index f02d7cd..497216c 100644
--- a/Arbiter-Android/assets/www/js/Arbiter/Geolocation/Geolocation.js
+++ b/Arbiter-Android/assets/www/js/Arbiter/Geolocation/Geolocation.js
@@ -1,15 +1,27 @@
Arbiter.Geolocation = function(context, lowAccuracyCallback, highAccuracyCallback, onFailure){
+ this.testing = false;
this.callbackContext = context;
this.lowAccuracyCallback = lowAccuracyCallback;
this.highAccuracyCallback = highAccuracyCallback;
this.onFailure = onFailure;
+ this.gotResult = false;
+ this.executedFailureCallback = false;
+
this.options = {
- timeout: 5000,
+ timeout: 10000,
maximumAge: 3000
};
};
+Arbiter.Geolocation.prototype.onFailed = function(e){
+
+ if(!this.gotResult && !this.executedFailureCallback){
+ this.executedFailureCallback = true;
+ this.onFailure.call(this.callbackContext, e);
+ }
+};
+
Arbiter.Geolocation.prototype.getLocation = function(){
if(Arbiter.Util.funcExists(this.lowAccuracyCallback)){
@@ -18,57 +30,68 @@ Arbiter.Geolocation.prototype.getLocation = function(){
var context = this;
- window.setTimeout(function(){
+ var highAccuracy = function(){
if(Arbiter.Util.funcExists(context.highAccuracyCallback)){
context.getCurrentLocationHighAccuracy();
}
- }, 2000);
+ };
+
+ highAccuracy();
};
-Arbiter.Geolocation.prototype.getCurrentLocation = function(onSuccess, onFailure){
-
- /*navigator.geolocation.getCurrentPosition(function(position){
- if(Arbiter.Util.funcExists(onSuccess)){
- onSuccess(position);
- }
- }, function(e){
- if(Arbiter.Util.funcExists(onFailure)){
- onFailure(e);
- }
- }, this.options);*/
-
- var pos = {
-
- };
+Arbiter.Geolocation.prototype.getCurrentLocation = function(onSuccess){
- if(this.options.enableHighAccuracy === true){
- pos.coords = {
- longitude: "-77.35760093",
- latitude: "38.95602994"
+ if(this.testing){
+ var pos = {
+
};
+
+ if(this.options.enableHighAccuracy === true){
+ pos.coords = {
+ longitude: "-77.35760093",
+ latitude: "38.95602994"
+ };
+ }else{
+ pos.coords = {
+ longitude: "-77.35702157",
+ latitude: "38.95762344"
+ };
+ }
+
+ var context = this;
+
+ window.setTimeout(function(){
+ if(Arbiter.Util.funcExists(onSuccess)){
+ onSuccess(pos);
+ }
+ }, 4000);
}else{
- pos.coords = {
- longitude: "-77.35702157",
- latitude: "38.95762344"
- };
+ var context = this;
+
+ navigator.geolocation.getCurrentPosition(function(position){
+
+ context.gotResult = true;
+
+ if(Arbiter.Util.funcExists(onSuccess)){
+ onSuccess(position);
+ }
+ }, function(e){
+
+ context.onFailed(e);
+ }, this.options);
}
-
- var context = this;
-
- window.setTimeout(function(){
- if(Arbiter.Util.funcExists(onSuccess)){
- onSuccess.call(context.callbackContext, pos);
- }
- }, 4000);
};
Arbiter.Geolocation.prototype.getCurrentLocationLowAccuracy = function(){
var context = this;
- delete this.options.enableHighAccuracy;
+ this.options.enableHighAccuracy = false;
- this.getCurrentLocation(this.lowAccuracyCallback, this.onFailure);
+ this.getCurrentLocation(function(pos){
+
+ context.lowAccuracyCallback.call(context.callbackContext, pos);
+ });
};
Arbiter.Geolocation.prototype.getCurrentLocationHighAccuracy = function(){
@@ -77,5 +100,8 @@ Arbiter.Geolocation.prototype.getCurrentLocationHighAccuracy = function(){
this.options.enableHighAccuracy = true;
- this.getCurrentLocation(this.highAccuracyCallback, this.onFailure);
+ this.getCurrentLocation(function(pos){
+
+ context.highAccuracyCallback.call(context.callbackContext, pos);
+ });
};
\ No newline at end of file
diff --git a/Arbiter-Android/assets/www/js/Arbiter/index/main.js b/Arbiter-Android/assets/www/js/Arbiter/index/main.js
index a87ad81..7b13ccf 100644
--- a/Arbiter-Android/assets/www/js/Arbiter/index/main.js
+++ b/Arbiter-Android/assets/www/js/Arbiter/index/main.js
@@ -3,6 +3,22 @@ var app = (function() {
var waitFuncs = [];
var ArbiterInitialized = false;
+ var findMeOOM = function(){
+
+ var map = Arbiter.Map.getMap();
+
+ var aoiLayer = map.getLayersByName(Arbiter.AOI)[0];
+
+ if(Arbiter.Util.existsAndNotNull(aoiLayer)){
+
+ var findme = new Arbiter.FindMe(map, aoiLayer, true);
+
+ findme.resume();
+ }else{
+ console.log("There is no aoi layer!");
+ }
+ };
+
/**
* On device ready
*/
@@ -78,7 +94,12 @@ var app = (function() {
Arbiter.Loaders.LayersLoader.addEventTypes();
- Arbiter.Loaders.LayersLoader.load();
+ Arbiter.Loaders.LayersLoader.load(function(){
+
+ findMeOOM();
+ }, function(e){
+ console.log("Could not load layers during initialization: " + JSON.stringify(e));
+ });
for ( var i = 0; i < waitFuncs.length; i++) {
waitFuncs[i].call();
diff --git a/Arbiter-Android/assets/www/main.html b/Arbiter-Android/assets/www/main.html
index b3199cf..9da637e 100644
--- a/Arbiter-Android/assets/www/main.html
+++ b/Arbiter-Android/assets/www/main.html
@@ -84,6 +84,7 @@
+
diff --git a/Arbiter-Android/res/values-es/strings.xml b/Arbiter-Android/res/values-es/strings.xml
index bfd896f..1f8ab7b 100644
--- a/Arbiter-Android/res/values-es/strings.xml
+++ b/Arbiter-Android/res/values-es/strings.xml
@@ -177,5 +177,5 @@
Fotos que no se pudieron cargar:
Fotos que no pudieron descargar:
Reintente
-
+ Error de geolocalización
diff --git a/Arbiter-Android/res/values/strings.xml b/Arbiter-Android/res/values/strings.xml
index f43dab5..b4a2880 100644
--- a/Arbiter-Android/res/values/strings.xml
+++ b/Arbiter-Android/res/values/strings.xml
@@ -177,4 +177,5 @@
Media that failed to upload:
Media that failed to download:
Retry
+ Geolocation Error
diff --git a/Arbiter-Android/src/com/lmn/Arbiter_Android/CordovaPlugins/ArbiterCordova.java b/Arbiter-Android/src/com/lmn/Arbiter_Android/CordovaPlugins/ArbiterCordova.java
index 77f89a4..9a975fd 100644
--- a/Arbiter-Android/src/com/lmn/Arbiter_Android/CordovaPlugins/ArbiterCordova.java
+++ b/Arbiter-Android/src/com/lmn/Arbiter_Android/CordovaPlugins/ArbiterCordova.java
@@ -239,6 +239,11 @@ public void run(){
return true;
}else if("dismissDownloadingSchemasProgress".equals(action)){
+ return true;
+ }else if("alertGeolocationError".equals(action)){
+
+ alertGeolocationError(args.getString(0));
+
return true;
}
@@ -246,6 +251,24 @@ public void run(){
return false;
}
+ private void alertGeolocationError(String msg){
+ final Activity activity = cordova.getActivity();
+
+ final AlertDialog.Builder builder = new AlertDialog.Builder(activity);
+
+ builder.setIcon(R.drawable.icon);
+ builder.setTitle(R.string.geolocation_error);
+ builder.setMessage(msg);
+ builder.setPositiveButton(android.R.string.ok, null);
+
+ activity.runOnUiThread(new Runnable(){
+ @Override
+ public void run(){
+ builder.create().show();
+ }
+ });
+ }
+
private void showDownloadingSchemasProgress(final String count){
final Activity activity = cordova.getActivity();
String title = activity.getResources().getString(R.string.downloading_schemas);