/*
 * Copyright 2014 Randy McEoin
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package net.mceoin.cominghome;

public class LocationUtils {

    /**
     * Calculate distance in meters between two points.
     *
     * @param lat1 Latitude for point 1
     * @param lng1 Longitude for point 1
     * @param lat2 Latitude for point 2
     * @param lng2 Longitude for point 2
     * @return distance in meters
     */
    public static float distFrom(double lat1, double lng1, double lat2, double lng2) {
        double earthRadius = 3958.75;
        double dLat = Math.toRadians(lat2 - lat1);
        double dLng = Math.toRadians(lng2 - lng1);
        double a = Math.sin(dLat / 2) * Math.sin(dLat / 2) +
                Math.cos(Math.toRadians(lat1)) * Math.cos(Math.toRadians(lat2)) *
                        Math.sin(dLng / 2) * Math.sin(dLng / 2);
        double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
        double dist = earthRadius * c;

        int meterConversion = 1609;

        return (float) (dist * meterConversion);
    }

/*
    public static float distFrom(Location location1, Location location2) {
        return distFrom(location1.getLatitude(), location1.getLongitude(),
                location2.getLatitude(), location2.getLongitude());
    }
*/

}

@@ -622,16 +622,240 @@
 ghome;%0A%0A
+import android.content.Context;%0Aimport android.location.Location;%0Aimport android.support.annotation.NonNull;%0A%0Aimport net.mceoin.cominghome.geofence.SimpleGeofence;%0Aimport net.mceoin.cominghome.geofence.SimpleGeofenceStore;%0A%0A
 public c
@@ -1790,63 +1790,290 @@
  %7D%0A%0A
-/
+    /*
 *%0A    
+ 
-public static f
+* Calculate the distance from home in meters.%0A     *%0A     * @param context  Application context%0A     * @param 
 lo
+c
 at
- distFrom(Location location1,
+ion Location to compare to home location%0A     * @return Distance in meters%0A     */%0A    public static float distFromHome(@NonNull Context context, @NonNull
  Loc
@@ -2086,17 +2086,16 @@
 location
-2
 ) %7B%0A    
@@ -2102,32 +2102,34 @@
     
-return distFrom(
+double latitude = 
 location
 1.ge
@@ -2120,25 +2120,24 @@
 e = location
-1
 .getLatitude
@@ -2130,33 +2130,60 @@
 on.getLatitude()
-,
+;%0A        double longitude =
  location1.getLo
@@ -2175,17 +2175,16 @@
 location
-1
 .getLong
@@ -2190,17 +2190,18 @@
 gitude()
-,
+;%0A
 %0A       
@@ -2205,50 +2205,370 @@
     
-        location2.getL
+SimpleGeofenceStore mGeofenceStorage;%0A        mGeofenceStorage = new SimpleGeofenceStore(context);%0A        SimpleGeofence geofence = mGeofenceStorage.getGeofence(MainActivity.FENCE_HOME);%0A%0A        if (geofence == null) %7B%0A            return -1;%0A        %7D%0A%0A        return LocationUtils.distFrom(l
 atitude
-()
 , lo
-cation2
+ngitude, geofence.getLatitude(),%0A                geofence
 .get
@@ -2591,10 +2591,6 @@
   %7D%0A
-*/%0A%0A
 %7D%0A

Add distFromHome()