0

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();
        }
Adnan
  • 5,025
  • 5
  • 25
  • 44
anu_r
  • 1,602
  • 7
  • 30
  • 61
  • try [this](http://javapapers.com/android/get-current-location-in-android/) – user3355820 Mar 18 '14 at 11:40
  • I have used some parts of that code.I am getting my current location but when I change my location I get the same coordinates – anu_r Mar 18 '14 at 12:02
  • see http://stackoverflow.com/questions/12618484/getting-current-location-longitude-and-latitude-without-change-my-position – user3355820 Mar 18 '14 at 12:22

0 Answers0