package com.hfad.odometer;

import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Binder;
import android.os.Bundle;
import android.os.IBinder;

public class OdometerService extends Service {

    private final IBinder binder = new OdometerBinder();
    private static double distanceInMeters;
    private static Location lastLocation = null;

    public class OdometerBinder extends Binder {
        OdometerService getOdometer() {
            return OdometerService.this;
        }
    }

    @Override
    public IBinder onBind(Intent intent) {
        return binder;
    }

    @Override
    public void onCreate() {
        LocationListener listener = new LocationListener() {
                @Override
                public void onLocationChanged(Location location) {
                    if (lastLocation == null) {
                        lastLocation = location;
                    }
                    distanceInMeters += location.distanceTo(lastLocation);
                    lastLocation = location;
                }

                @Override
                public void onProviderDisabled(String arg0) {}

                @Override
                public void onProviderEnabled(String arg0) {}

                @Override
                public void onStatusChanged(String arg0, int arg1, Bundle bundle) {}
            };
        LocationManager locManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
        locManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000, 1, listener);
    }

    public double getMiles() {
        return this.distanceInMeters / 1609.344;
    }
}

@@ -506,16 +506,95 @@
  = null;
+%0A    private LocationListener listener;%0A    private LocationManager locManager;
 %0A%0A    pu
@@ -872,33 +872,16 @@
         
-LocationListener 
 listener
@@ -1572,32 +1572,16 @@
         
-LocationManager 
 locManag
@@ -1741,24 +1741,247 @@
 er);%0A    %7D%0A%0A
+    @Override%0A    public void onDestroy() %7B%0A        if (locManager != null && listener != null) %7B%0A            locManager.removeUpdates(listener);%0A            locManager = null;%0A            listener = null;%0A        %7D%0A    %7D%0A%0A
     public d

Fix bug that left the odometer service running.