Heads up! This post was written 12 years ago. Some information might be outdated or may have changed since then.
private double[] GetLastLocationGPS() {
LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
List providers = lm.getProviders(true);
Location l = null;
for (int i = providers.size() - 1; i >= 0; i--) {
l = lm.getLastKnownLocation(providers.get(i));
if (l != null)
break;
}
double[] gps = new double[2];
if (l != null) {
gps[0] = l.getLatitude();
gps[1] = l.getLongitude();
}
return gps;
}