mirror of
https://github.com/apache/cordova-android.git
synced 2025-02-27 04:42:51 +08:00
GeoBroker checks if location service avialable for device first.
This commit is contained in:
parent
c52dc10c9e
commit
e575212c49
@ -59,36 +59,43 @@ public class GeoBroker extends Plugin {
|
|||||||
this.networkListener = new NetworkListener(this.locationManager, this);
|
this.networkListener = new NetworkListener(this.locationManager, this);
|
||||||
this.gpsListener = new GPSListener(this.locationManager, this);
|
this.gpsListener = new GPSListener(this.locationManager, this);
|
||||||
}
|
}
|
||||||
PluginResult.Status status = PluginResult.Status.NO_RESULT;
|
|
||||||
String message = "";
|
|
||||||
PluginResult result = new PluginResult(status, message);
|
|
||||||
result.setKeepCallback(true);
|
|
||||||
|
|
||||||
try {
|
PluginResult.Status status = PluginResult.Status.NO_RESULT;
|
||||||
if (action.equals("getLocation")) {
|
String message = "Location API is not available for this device.";
|
||||||
boolean enableHighAccuracy = args.getBoolean(0);
|
PluginResult result = new PluginResult(status, message);
|
||||||
int maximumAge = args.getInt(1);
|
|
||||||
Location last = this.locationManager.getLastKnownLocation((enableHighAccuracy ? LocationManager.GPS_PROVIDER : LocationManager.NETWORK_PROVIDER));
|
if ( locationManager.isProviderEnabled( LocationManager.GPS_PROVIDER ) ||
|
||||||
// Check if we can use lastKnownLocation to get a quick reading and use less battery
|
locationManager.isProviderEnabled( LocationManager.NETWORK_PROVIDER )) {
|
||||||
if ((System.currentTimeMillis() - last.getTime()) <= maximumAge) {
|
|
||||||
result = new PluginResult(PluginResult.Status.OK, this.returnLocationJSON(last));
|
result.setKeepCallback(true);
|
||||||
} else {
|
|
||||||
this.getCurrentLocation(callbackId, enableHighAccuracy);
|
try {
|
||||||
}
|
if (action.equals("getLocation")) {
|
||||||
}
|
boolean enableHighAccuracy = args.getBoolean(0);
|
||||||
else if (action.equals("addWatch")) {
|
int maximumAge = args.getInt(1);
|
||||||
String id = args.getString(0);
|
Location last = this.locationManager.getLastKnownLocation((enableHighAccuracy ? LocationManager.GPS_PROVIDER : LocationManager.NETWORK_PROVIDER));
|
||||||
boolean enableHighAccuracy = args.getBoolean(1);
|
// Check if we can use lastKnownLocation to get a quick reading and use less battery
|
||||||
this.addWatch(id, callbackId, enableHighAccuracy);
|
if ((System.currentTimeMillis() - last.getTime()) <= maximumAge) {
|
||||||
}
|
result = new PluginResult(PluginResult.Status.OK, this.returnLocationJSON(last));
|
||||||
else if (action.equals("clearWatch")) {
|
} else {
|
||||||
String id = args.getString(0);
|
this.getCurrentLocation(callbackId, enableHighAccuracy);
|
||||||
this.clearWatch(id);
|
}
|
||||||
}
|
}
|
||||||
} catch (JSONException e) {
|
else if (action.equals("addWatch")) {
|
||||||
result = new PluginResult(PluginResult.Status.JSON_EXCEPTION, e.getMessage());
|
String id = args.getString(0);
|
||||||
|
boolean enableHighAccuracy = args.getBoolean(1);
|
||||||
|
this.addWatch(id, callbackId, enableHighAccuracy);
|
||||||
|
}
|
||||||
|
else if (action.equals("clearWatch")) {
|
||||||
|
String id = args.getString(0);
|
||||||
|
this.clearWatch(id);
|
||||||
|
}
|
||||||
|
} catch (JSONException e) {
|
||||||
|
result = new PluginResult(PluginResult.Status.JSON_EXCEPTION, e.getMessage());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void clearWatch(String id) {
|
private void clearWatch(String id) {
|
||||||
|
Loading…
Reference in New Issue
Block a user