Sfoglia il codice sorgente

1.修改Android Apex Drivers位置获取。

Pen Li 7 anni fa
parent
commit
bd79a83505

+ 1 - 4
ApexDrivers/RAUtilsLibrary/src/main/java/com/usai/redant/rautils/location/SystemLocation.java

@@ -179,10 +179,7 @@ public class SystemLocation {
 
 
     private void handleMyLocation(Location location) {
     private void handleMyLocation(Location location) {
 
 
-        if (location == null)
-            return;
-
-        if (adjustLocation) {
+        if (adjustLocation && location != null) {
 
 
             double lat = location.getLatitude();
             double lat = location.getLatitude();
             double lon = location.getLongitude();
             double lon = location.getLongitude();

+ 32 - 0
ApexDrivers/RAUtilsLibrary/src/main/java/com/usai/redant/rautils/service/RAService.java

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

+ 8 - 4
ApexDrivers/apexdriverslib/src/main/java/com/usai/redant/apexdrivers/ApexDriverApplication.java

@@ -301,7 +301,11 @@ public class ApexDriverApplication extends Application {
     }
     }
 
 
     public Location getCurrentLocation() {
     public Location getCurrentLocation() {
-        return mService.RequestCachedLocation();
+        return mService.getCurrentLocation();
+    }
+
+    public Location getLastKnownLocation() {
+        return mService.getLastKnownLocation();
     }
     }
 
 
     public boolean isLogin() {
     public boolean isLogin() {
@@ -643,7 +647,7 @@ public class ApexDriverApplication extends Application {
                                 @Override
                                 @Override
                                 public void onClick(DialogInterface dialog, int which) {
                                 public void onClick(DialogInterface dialog, int which) {
 
 
-                                    Location location = getCurrentLocation();
+                                    Location location = getLastKnownLocation();
                                     reportLocationForOrder(location,orderId,locationId);
                                     reportLocationForOrder(location,orderId,locationId);
                                 }
                                 }
                             })
                             })
@@ -662,7 +666,7 @@ public class ApexDriverApplication extends Application {
             break;
             break;
             case BackgroundReportTypeAllow: {
             case BackgroundReportTypeAllow: {
 
 
-                Location location = getCurrentLocation();
+                Location location = getLastKnownLocation();
 
 
                 reportLocationForOrder(location,orderId,locationId);
                 reportLocationForOrder(location,orderId,locationId);
             }
             }
@@ -697,7 +701,7 @@ public class ApexDriverApplication extends Application {
 
 
                         if (backgroundReportType == BackgroundReportTypeAllow) {
                         if (backgroundReportType == BackgroundReportTypeAllow) {
 
 
-                            Location location = getCurrentLocation();
+                            Location location = getLastKnownLocation();
                             reportLocationForOrder(location,orderID, locationId);
                             reportLocationForOrder(location,orderID, locationId);
 
 
                         } else {
                         } else {