1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
|
Location location = null;
double longitude ;
double lattitude ;
LocationManager mLocationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
if(mLocationManager.isProviderEnabled(LocationManager.GPS_PROVIDER))
{
mLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0,0, this);
location = mLocationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
}
else
{
mLocationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0,0, this);
location = mLocationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
}
List<String> providers = mLocationManager.getProviders(true);
if(location == null)
{
for (int i=providers.size()-1; i>=0; i--)
{
mLocationManager.requestLocationUpdates(providers.get(i), 0, 0, this);
location = mLocationManager.getLastKnownLocation(providers.get(i));
if (location != null) break;
}
}
longitude = location.getLongitude();
lattitude = location.getLatitude(); |
Partager