added get cached location method

This commit is contained in:
Mariotaku Lee 2015-06-14 14:25:46 +08:00
parent 6abbdb2c6a
commit b1c7676fe9
1 changed files with 19 additions and 0 deletions

View File

@ -48,6 +48,8 @@ import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.NinePatchDrawable;
import android.graphics.drawable.TransitionDrawable;
import android.location.Location;
import android.location.LocationManager;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.Uri;
@ -3877,4 +3879,21 @@ public final class Utils implements Constants {
}
}
public Location getCachedLocation(Context context) {
final LocationManager lm = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
Location location = null;
try {
location = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER);
} catch (Exception ignore) {
}
if (location != null) return location;
try {
location = lm.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
} catch (Exception ignore) {
}
return location;
}
}