package eic.beike.projectx.android;

import android.location.Criteria;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.util.Log;

/**
 * @author adam
 */
public class LocationFinder implements LocationListener {

    private LocationManager locationManager;

    public static final Location position = new Location("");

    public LocationFinder(LocationManager lm) {

        Log.d("LocationFinder", "Initial location: " + position.toString());

        locationManager = lm;

        Log.d("LocationFinder", "Setting up listener");
        locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER,0, 1,this);
        locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 1, this);
    }


    public void stop() {
        locationManager.removeUpdates(this);
    }


    @Override
    public void onLocationChanged(Location location) {
        if (location != null && location.getAccuracy() < 500) {
            //location wasn't null and we're 68% certain that it's correct to 500 meters.
            position.set(location);
            Log.d("LocationFinder", "New location: " + position.toString());
        }
    }

    // Required unused functions
    @Override
    public void onStatusChanged(String provider, int status, Bundle extras) {}
    @Override
    public void onProviderEnabled(String provider) {}
    @Override
    public void onProviderDisabled(String provider) {}

    public static Location getLocation() {
        return position;
    }

    public static double getLongitude() {
        return position.getLongitude();
    }

    public static double getLatitude() {
        return position.getLatitude();
    }
}


@@ -34,42 +34,8 @@
 d;%0A%0A
-import android.location.Criteria;%0A
 impo
@@ -64,16 +64,16 @@
 cation;%0A
+
 import a
@@ -203,16 +203,310 @@
 g;%0A%0A/**%0A
+ * Keeps track of the gps position of the phone. We start listening%0A * as soon as the app starts and let any class that's interested get%0A * the android Location. The reason we do this is because we had trouble%0A * getting a gps fix fast enough so we give the location finder a head%0A * start.%0A *%0A
  * @auth
@@ -623,29 +623,30 @@
 ager;%0A%0A    p
-ublic
+rivate
  static fina

Add class description.