|
|
@@ -63,6 +63,9 @@ public abstract class RAService extends Service {
|
|
|
|
|
|
private static final boolean System_Location_Flag = true;
|
|
|
|
|
|
+ private Location mCurrentLocation; // 当前定位位置,可为空
|
|
|
+ private Location mLastNotNullLocation; // 最后一次获取的非空Location
|
|
|
+
|
|
|
// service setup
|
|
|
protected int service_flag = FLAG_SERVICE_NONE;
|
|
|
private IntentFilter msgFilter = new IntentFilter();
|
|
|
@@ -625,6 +628,31 @@ public abstract class RAService extends Service {
|
|
|
|
|
|
}
|
|
|
|
|
|
+ private void setCurrentLocation(Location location) {
|
|
|
+ mCurrentLocation = location;
|
|
|
+ if (location != null) {
|
|
|
+ mLastNotNullLocation = location;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (locationCallback != null) {
|
|
|
+ locationCallback.onLocationChanged(location);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public Location getCurrentLocation() {
|
|
|
+ if ((service_flag & FLAG_SERVICE_LOCATION) == FLAG_SERVICE_LOCATION) {
|
|
|
+ return mCurrentLocation;
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ public Location getLastKnownLocation() {
|
|
|
+ if ((service_flag & FLAG_SERVICE_LOCATION) == FLAG_SERVICE_LOCATION) {
|
|
|
+ return mLastNotNullLocation;
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
public void initLocation() {
|
|
|
|
|
|
if (System_Location_Flag) {
|
|
|
@@ -635,6 +663,7 @@ public abstract class RAService extends Service {
|
|
|
public void onLocationChanged(Location location) {
|
|
|
|
|
|
Log.d(TAG, "onLocationChanged: " + location);
|
|
|
+ setCurrentLocation(location);
|
|
|
}
|
|
|
});
|
|
|
|
|
|
@@ -651,6 +680,9 @@ public abstract class RAService extends Service {
|
|
|
|
|
|
Log.i(TAG, "onLocationResult: " + locationResult.getLastLocation());
|
|
|
// onNewLocation(locationResult.getLastLocation());
|
|
|
+
|
|
|
+ Location location = locationResult.getLastLocation();
|
|
|
+ setCurrentLocation(location);
|
|
|
}
|
|
|
};
|
|
|
|