I am developing an app in which I have to keep getting the coordinates when the user changes his location. I think my coordinates are not getting refreshed. Can anyone suggest how can I get the coordinates when location changes? My codes are as follows:
class Ser extends Service implements LocationListener
{
public Location getLocation(String provider) {
if (locationManager.isProviderEnabled(provider)) {
locationManager.requestLocationUpdates(provider,
MIN_TIME_FOR_UPDATE, MIN_DISTANCE_FOR_UPDATE, this);
location = locationManager.getLastKnownLocation(provider);
double latitude = location.getLatitude();
double longitude = location.getLongitude();
String l1=String.valueOf(latitude);
String l2=String.valueOf(longitude);
return location;
}
}
@Override
public void onLocationChanged(Location location) {
locationManager = (LocationManager) getApplicationContext().getSystemService(LOCATION_SERVICE);
getLocation(LocationManager.NETWORK_PROVIDER);
isGPSEnabled = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
isNetworkEnabled = locationManager
.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
if(isNetworkEnabled==true)
{
getLocation(LocationManager.NETWORK_PROVIDER);
}
else if(isGPSEnabled==true)
{
getLocation(LocationManager.GPS_PROVIDER);
}
else
{
cellid();
}