@@ -0,0 +1,3643 @@
+package edu.illinois.strollsafe.util;%0Aimport android.app.Activity;%0Aimport android.location.Location;%0Aimport android.os.Bundle;%0A%0Aimport com.google.android.gms.common.ConnectionResult;%0Aimport com.google.android.gms.common.api.GoogleApiClient;%0Aimport com.google.android.gms.location.FusedLocationProviderApi;%0Aimport com.google.android.gms.location.LocationListener;%0Aimport com.google.android.gms.location.LocationRequest;%0Aimport com.google.android.gms.location.LocationServices;%0A%0Aimport java.util.concurrent.Executors;%0Aimport java.util.concurrent.TimeUnit;%0A%0Apublic class FusedLocationService implements%0A        LocationListener,%0A        GoogleApiClient.ConnectionCallbacks,%0A        GoogleApiClient.OnConnectionFailedListener %7B%0A    private static final long INTERVAL = 1000 * 30;%0A    private static final long FASTEST_INTERVAL = 1000 * 5;%0A    private static final long ONE_MIN = 1000 * 60;%0A    private static final long REFRESH_TIME = ONE_MIN * 5;%0A    private static final float MINIMUM_ACCURACY = 50.0f;%0A    Activity locationActivity;%0A    private LocationRequest locationRequest;%0A    private GoogleApiClient googleApiClient;%0A    private Location location;%0A    private FusedLocationProviderApi fusedLocationProviderApi = LocationServices.FusedLocationApi;%0A%0A    public FusedLocationService(Activity locationActivity) %7B%0A        locationRequest = LocationRequest.create();%0A        locationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);%0A        locationRequest.setInterval(INTERVAL);%0A        locationRequest.setFastestInterval(FASTEST_INTERVAL);%0A        this.locationActivity = locationActivity;%0A%0A        googleApiClient = new GoogleApiClient.Builder(locationActivity)%0A                .addApi(LocationServices.API)%0A                .addConnectionCallbacks(this)%0A                .addOnConnectionFailedListener(this)%0A                .build();%0A%0A        if (googleApiClient != null) %7B%0A            googleApiClient.connect();%0A        %7D%0A    %7D%0A%0A    @Override%0A    public void onConnected(Bundle connectionHint) %7B%0A        Location currentLocation = fusedLocationProviderApi.getLastLocation(googleApiClient);%0A        if (currentLocation != null && currentLocation.getTime() %3E REFRESH_TIME) %7B%0A            location = currentLocation;%0A        %7D else %7B%0A            fusedLocationProviderApi.requestLocationUpdates(googleApiClient, locationRequest, this);%0A            // Schedule a Thread to unregister location listeners%0A            Executors.newScheduledThreadPool(1).schedule(new Runnable() %7B%0A                @Override%0A                public void run() %7B%0A                    fusedLocationProviderApi.removeLocationUpdates(googleApiClient,%0A                            FusedLocationService.this);%0A                %7D%0A            %7D, ONE_MIN, TimeUnit.MILLISECONDS);%0A        %7D%0A    %7D%0A%0A    @Override%0A    public void onLocationChanged(Location location) %7B%0A        //if the existing location is empty or%0A        //the current location accuracy is greater than existing accuracy%0A        //then store the current location%0A        if (null == this.location %7C%7C location.getAccuracy() %3C this.location.getAccuracy()) %7B%0A            this.location = location;%0A            //if the accuracy is not better, remove all location updates for this listener%0A            if (this.location.getAccuracy() %3C MINIMUM_ACCURACY) %7B%0A                fusedLocationProviderApi.removeLocationUpdates(googleApiClient, this);%0A            %7D%0A        %7D%0A    %7D%0A%0A    public Location getLocation() %7B%0A        return this.location;%0A    %7D%0A%0A    @Override%0A    public void onConnectionSuspended(int i) %7B%0A%0A    %7D%0A%0A    @Override%0A    public void onConnectionFailed(ConnectionResult connectionResult) %7B%0A%0A    %7D%0A%7D

Add location services