->Below Class is Find Current Location.
public class CurrentLocation {
private LocationManager locationManager;
private Context context;
private Location location;
private LocationListener locationListener;
public CurrentLocation(Context ctx) {
this.context = ctx;
locationManager = (LocationManager) context
.getSystemService(Context.LOCATION_SERVICE);
@SuppressWarnings("unused")
List<string> providers = locationManager.getAllProviders();
Criteria locationCritera = new Criteria();
String providerName = locationManager.getBestProvider(locationCritera,
true);
location = locationManager.getLastKnownLocation(providerName);
locationListener = new MyLocationListener();
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0,
0, locationListener);
location = locationManager.getLastKnownLocation(providerName);
}
public Location getLocation() {
return location;
}
}
->Below Class is MyLocationListner.
public class MyLocationListener implements LocationListener {
@Override
public void onLocationChanged(Location loc) {
}
@Override
public void onProviderDisabled(String arg0) {
}
@Override
public void onProviderEnabled(String provider) {
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
}
}
->I Get Current Location.
CurrentLocation currLocation = new CurrentLocation(MainActivity.this);
Location location = currLocation.getLocation();
Toast.makeText(MainActivity.java,"Lat "+location.getLatitude+" Long : "+location.getLongitude,
Toast.LENGTH_LONG)
.show();
But I have Problem...
When I Install Application That Time give correct Location Latitude and Longitude,But when I
go to Onther city and run installed Application that time it give me previous Location ,mean Last Known Location latitude and Longitude.Insort my Location is Not Updated when Location Change.
please Tell me how update Location,or refresh last known location?